
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Golang · 尹自强.Note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="尹自强">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-prism/prism.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-advanced-emoji/emoji-website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../styles/yzq.css">
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Golang.html" />
    
    
    <link rel="prev" href="../" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://github.com/554393109" target="_blank" class="custom-link">作者GitHub</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    在线笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="Golang.html">
            
                <a href="Golang.html">
            
                    
                    Golang
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="Golang.html">
            
                <a href="Golang.html#安装与配置">
            
                    
                    安装与配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="Golang.html">
            
                <a href="Golang.html#语法">
            
                    
                    语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="Golang.html">
            
                <a href="Golang.html#常用命令">
            
                    
                    常用命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="Git.html">
            
                <a href="Git.html">
            
                    
                    Git
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Git.html">
            
                <a href="Git.html#版本管理流程">
            
                    
                    版本管理流程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Git.html">
            
                <a href="Git.html#常用命令">
            
                    
                    常用命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="GitBook.html">
            
                <a href="GitBook.html">
            
                    
                    GitBook
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="GitBook.html">
            
                <a href="GitBook.html#项目结构">
            
                    
                    项目结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="GitBook.html">
            
                <a href="GitBook.html#常用插件">
            
                    
                    常用插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="GitBook.html">
            
                <a href="GitBook.html#常用命令">
            
                    
                    常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="GitBook.html">
            
                <a href="GitBook.html#常见问题">
            
                    
                    常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="Nuget.html">
            
                <a href="Nuget.html">
            
                    
                    Nuget
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="Nuget.html">
            
                <a href="Nuget.html#私有源服务器搭建">
            
                    
                    私有源服务器搭建
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="Nuget.html">
            
                <a href="Nuget.html#nuspec文件解析">
            
                    
                    nuspec文件解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Nuget.html">
            
                <a href="Nuget.html#常用命令">
            
                    
                    常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Nuget.html">
            
                <a href="Nuget.html#相关资源">
            
                    
                    相关资源
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="Npm.html">
            
                <a href="Npm.html">
            
                    
                    NPM
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="Npm.html">
            
                <a href="Npm.html#常用命令">
            
                    
                    常用命令
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="SiteConsole.html">
            
                <a href="SiteConsole.html">
            
                    
                    网站Console
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="Docker.html">
            
                <a href="Docker.html">
            
                    
                    Docker
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="Docker.html">
            
                <a href="Docker.html#Dockerfile">
            
                    
                    Dockerfile
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="Docker.html">
            
                <a href="Docker.html#常用命令">
            
                    
                    常用命令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="Docker.html">
            
                <a href="Docker.html#常用镜像">
            
                    
                    常用镜像
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="Docker.html">
            
                <a href="Docker.html#相关资源">
            
                    
                    相关资源
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="Skill.html">
            
                <a href="Skill.html">
            
                    
                    技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="Tools.html">
            
                <a href="Tools.html">
            
                    
                    常用工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="bio.html">
            
                <a href="bio.html">
            
                    
                    个人履历
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Golang</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x5B89;&#x88C5;&#x4E0E;&#x914D;&#x7F6E;"><b>1. </b>&#x5B89;&#x88C5;&#x4E0E;&#x914D;&#x7F6E;</a></li><ul><li><span class="title-icon "></span><a href="#&#x4E0B;&#x8F7D;&#x5E76;&#x5B89;&#x88C5;golang&#x7A0B;&#x5E8F;"><b>1.1. </b>&#x4E0B;&#x8F7D;&#x5E76;&#x5B89;&#x88C5;Golang&#x7A0B;&#x5E8F;</a></li><li><span class="title-icon "></span><a href="#&#x914D;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF08;&#x56FD;&#x5185;&#x955C;&#x50CF;&#x52A0;&#x901F;&#xFF09;"><b>1.2. </b>&#x914D;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF08;&#x56FD;&#x5185;&#x955C;&#x50CF;&#x52A0;&#x901F;&#xFF09;</a></li><li><span class="title-icon "></span><a href="#&#x914D;&#x7F6E;visual-studio-code"><b>1.3. </b>&#x914D;&#x7F6E;Visual Studio Code</a></li></ul><li><span class="title-icon "></span><a href="#&#x8BED;&#x6CD5;"><b>2. </b>&#x8BED;&#x6CD5;</a></li><ul><li><span class="title-icon "></span><a href="#&#x6570;&#x636E;&#x7C7B;&#x578B;"><b>2.1. </b>&#x6570;&#x636E;&#x7C7B;&#x578B;</a></li><li><span class="title-icon "></span><a href="#&#x5173;&#x952E;&#x5B57;"><b>2.2. </b>&#x5173;&#x952E;&#x5B57;</a></li><li><span class="title-icon "></span><a href="#&#x53D8;&#x91CF;&#x58F0;&#x660E;"><b>2.3. </b>&#x53D8;&#x91CF;&#x58F0;&#x660E;</a></li><li><span class="title-icon "></span><a href="#const&#x5E38;&#x91CF;&#x548C;iota&#x5B9E;&#x73B0;&#x679A;&#x4E3E;&#x6570;&#x503C;"><b>2.4. </b>const&#x5E38;&#x91CF;&#x548C;iota&#x5B9E;&#x73B0;&#x679A;&#x4E3E;&#x6570;&#x503C;</a></li><li><span class="title-icon "></span><a href="#&#x51FD;&#x6570;"><b>2.5. </b>&#x51FD;&#x6570;</a></li><ul><li><span class="title-icon "></span><a href="#&#x4F20;&#x53C2;&#x3001;&#x8FD4;&#x56DE;"><b>2.5.1. </b>&#x4F20;&#x53C2;&#x3001;&#x8FD4;&#x56DE;</a></li><li><span class="title-icon "></span><a href="#&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;"><b>2.5.2. </b>&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;</a></li><li><span class="title-icon "></span><a href="#&#x95ED;&#x5305;"><b>2.5.3. </b>&#x95ED;&#x5305;</a></li></ul><li><span class="title-icon "></span><a href="#import&#x5305;&#x548C;init&#x65B9;&#x6CD5;"><b>2.6. </b>import&#x5305;&#x548C;init&#x65B9;&#x6CD5;</a></li><li><span class="title-icon "></span><a href="#&#x6307;&#x9488;"><b>2.7. </b>&#x6307;&#x9488;</a></li><li><span class="title-icon "></span><a href="#defer-&#x5EF6;&#x540E;&#x6267;&#x884C;"><b>2.8. </b>defer &#x5EF6;&#x540E;&#x6267;&#x884C;</a></li><li><span class="title-icon "></span><a href="#&#x5B9A;&#x957F;&#x6570;&#x7EC4;"><b>2.9. </b>&#x5B9A;&#x957F;&#x6570;&#x7EC4;</a></li><li><span class="title-icon "></span><a href="#slice&#xFF08;&#x5207;&#x7247;&#x3001;&#x52A8;&#x6001;&#x6570;&#x7EC4;&#xFF09;"><b>2.10. </b>slice&#xFF08;&#x5207;&#x7247;&#x3001;&#x52A8;&#x6001;&#x6570;&#x7EC4;&#xFF09;</a></li><li><span class="title-icon "></span><a href="#map-&#x96C6;&#x5408;"><b>2.11. </b>map &#x96C6;&#x5408;</a></li><li><span class="title-icon "></span><a href="#struct-&#x7ED3;&#x6784;&#x4F53;"><b>2.12. </b>struct &#x7ED3;&#x6784;&#x4F53;</a></li><li><span class="title-icon "></span><a href="#oop-&#x9762;&#x5411;&#x5BF9;&#x8C61;"><b>2.13. </b>OOP &#x9762;&#x5411;&#x5BF9;&#x8C61;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5C01;&#x88C5;"><b>2.13.1. </b>&#x5C01;&#x88C5;</a></li><li><span class="title-icon "></span><a href="#&#x7EE7;&#x627F;"><b>2.13.2. </b>&#x7EE7;&#x627F;</a></li><li><span class="title-icon "></span><a href="#&#x591A;&#x6001;"><b>2.13.3. </b>&#x591A;&#x6001;</a></li></ul></ul><li><span class="title-icon "></span><a href="#&#x5E38;&#x7528;&#x547D;&#x4EE4;"><b>3. </b>&#x5E38;&#x7528;&#x547D;&#x4EE4;</a></li></ul></div><a href="#&#x5B89;&#x88C5;&#x4E0E;&#x914D;&#x7F6E;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><p><b style="font-size: 2em">Golang</b></p>
<p>&#x65E2;&#x7136;&#x9009;&#x62E9;&#x4F7F;&#x7528;Golang&#x5F00;&#x53D1;&#xFF0C;&#x79D1;&#x5B66;&#x4E0A;&#x7F51;&#x662F;&#x524D;&#x63D0;</p>
<hr>
<h1 id="&#x5B89;&#x88C5;&#x4E0E;&#x914D;&#x7F6E;"><a name="&#x5B89;&#x88C5;&#x4E0E;&#x914D;&#x7F6E;" class="anchor-navigation-ex-anchor" href="#&#x5B89;&#x88C5;&#x4E0E;&#x914D;&#x7F6E;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x5B89;&#x88C5;&#x4E0E;&#x914D;&#x7F6E;</h1>
<h2 id="&#x4E0B;&#x8F7D;&#x5E76;&#x5B89;&#x88C5;golang&#x7A0B;&#x5E8F;"><a name="&#x4E0B;&#x8F7D;&#x5E76;&#x5B89;&#x88C5;golang&#x7A0B;&#x5E8F;" class="anchor-navigation-ex-anchor" href="#&#x4E0B;&#x8F7D;&#x5E76;&#x5B89;&#x88C5;golang&#x7A0B;&#x5E8F;"><i class="fa fa-link" aria-hidden="true"></i></a>1.1. &#x4E0B;&#x8F7D;&#x5E76;&#x5B89;&#x88C5;Golang&#x7A0B;&#x5E8F;</h2>
<blockquote>
<p><strong>Go&#x5B98;&#x7F51;</strong><br><a href="https://go.dev/" target="_blank">https://go.dev/</a></p>
<p><strong>Go&#x56FD;&#x5185;&#x955C;&#x50CF;</strong><br><a href="https://goproxy.io/" target="_blank">https://goproxy.io/</a></p>
<p><strong>&#x4E03;&#x725B;</strong><br><a href="https://goproxy.cn/" target="_blank">https://goproxy.cn/</a></p>
</blockquote>
<h2 id="&#x914D;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF08;&#x56FD;&#x5185;&#x955C;&#x50CF;&#x52A0;&#x901F;&#xFF09;"><a name="&#x914D;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF08;&#x56FD;&#x5185;&#x955C;&#x50CF;&#x52A0;&#x901F;&#xFF09;" class="anchor-navigation-ex-anchor" href="#&#x914D;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF08;&#x56FD;&#x5185;&#x955C;&#x50CF;&#x52A0;&#x901F;&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>1.2. &#x914D;&#x7F6E;&#x73AF;&#x5883;&#x53D8;&#x91CF;&#xFF08;&#x56FD;&#x5185;&#x955C;&#x50CF;&#x52A0;&#x901F;&#xFF09;</h2>
<blockquote>
<p><strong>Windows</strong><br>1.&#x53F3;&#x952E; &#x6211;&#x7684;&#x7535;&#x8111; -&gt; &#x5C5E;&#x6027; -&gt; &#x9AD8;&#x7EA7;&#x7CFB;&#x7EDF;&#x8BBE;&#x7F6E; -&gt; &#x73AF;&#x5883;&#x53D8;&#x91CF;<br>2.&#x5728;&#x201C;&#x7528;&#x6237;&#x53D8;&#x91CF;&#x201D;&#x6216;&#x201C;&#x7CFB;&#x7EDF;&#x53D8;&#x91CF;&#x201D;&#x4E2D;&#x70B9;&#x51FB;&#x201D;&#x65B0;&#x5EFA;&#x201C;&#x6309;&#x94AE;<br>3.&#x201C;&#x53D8;&#x91CF;&#x540D;&#x201D;&#x5206;&#x522B;&#x4E3A;&#x201C;GOROOT&#x201D;&#x3001;&#x201C;GOPATH&#x201D;&#x3001;&#x201C;GOPROXY&#x201D;&#x3001;&#x201C;GO111MODULE&#x201D;&#x3001;&#x201C;GOSUMDB&#x201D;<br>4.&#x201C;&#x53D8;&#x91CF;&#x503C;&#x201D;&#x5206;&#x522B;&#x4E3A;&#x201C;Golang&#x6839;&#x76EE;&#x5F55;&#x201D;&#x3001;&#x201C;Golang&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&#x201D;&#x3001;&#x201C;on&#x201D;&#x3001;&#x201C;<a href="https://goproxy.cn,direct" target="_blank">https://goproxy.cn,direct</a>&#x201D;&#x3001;&#x201C;sum.golang.google.cn&#x201D;<br>5.&#x6700;&#x540E;&#x70B9;&#x51FB;&#x201C;&#x786E;&#x5B9A;&#x201D;&#x6309;&#x94AE;&#x4FDD;&#x5B58;&#x8BBE;&#x7F6E;</p>
<p><strong>Mac/Linux</strong><br>// &#x8BBE;&#x7F6E;&#x4F60;&#x7684; bash &#x73AF;&#x5883;&#x53D8;&#x91CF;<br>echo &quot;export GOROOT=Golang&#x6839;&#x76EE;&#x5F55;&quot; &gt;&gt; ~/.profile &amp;&amp; source ~/.profile<br>echo &quot;export GOPATH=Golang&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&quot; &gt;&gt; ~/.profile &amp;&amp; source ~/.profile<br>echo &quot;export GO111MODULE=on&quot; &gt;&gt; ~/.profile &amp;&amp; source ~/.profile<br>echo &quot;export GOPROXY=<a href="https://goproxy.cn,direct" target="_blank">https://goproxy.cn,direct</a>&quot; &gt;&gt; ~/.profile &amp;&amp; source ~/.profile<br>echo &quot;export GOSUMDB=sum.golang.google.cn&quot; &gt;&gt; ~/.profile &amp;&amp; source ~/.profile  </p>
<p>// &#x5982;&#x679C;&#x7EC8;&#x7AEF;&#x662F; zsh&#xFF0C;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;<br>echo &quot;export GOROOT=Golang&#x6839;&#x76EE;&#x5F55;&quot;&quot; &gt;&gt; ~/.zshrc &amp;&amp; source ~/.zshrc<br>echo &quot;export GOPATH=Golang&#x5DE5;&#x4F5C;&#x76EE;&#x5F55;&quot; &gt;&gt; ~/.zshrc &amp;&amp; source ~/.zshrc<br>echo &quot;export GO111MODULE=on&quot; &gt;&gt; ~/.zshrc &amp;&amp; source ~/.zshrc<br>echo &quot;export GOPROXY=<a href="https://goproxy.cn,direct" target="_blank">https://goproxy.cn,direct</a>&quot; &gt;&gt; ~/.zshrc &amp;&amp; source ~/.zshrc
echo &quot;export GOSUMDB=sum.golang.google.cn&quot; &gt;&gt; ~/.zshrc &amp;&amp; source ~/.zshrc  </p>
</blockquote>
<h2 id="&#x914D;&#x7F6E;visual-studio-code"><a name="&#x914D;&#x7F6E;visual-studio-code" class="anchor-navigation-ex-anchor" href="#&#x914D;&#x7F6E;visual-studio-code"><i class="fa fa-link" aria-hidden="true"></i></a>1.3. &#x914D;&#x7F6E;Visual Studio Code</h2>
<blockquote>
<p><strong>&#x5B89;&#x88C5;&#x6269;&#x5C55;&#x63D2;&#x4EF6;</strong><br>1.Go&#x6216;Go Nightly&#xFF08;Go Team at Google&#xFF09;<br>2.Code Runner&#xFF08;Jun Han&#xFF09;</p>
<p><strong>&#x5B89;&#x88C5;&#x8F85;&#x52A9;&#x5DE5;&#x5177;&#xFF08;&#x8BED;&#x6CD5;&#x63D0;&#x9192;&#x7B49;&#x5F00;&#x53D1;&#x5FC5;&#x8981;&#x529F;&#x80FD;&#xFF09;</strong><br>1.&#x201C;Ctrl+Shift+P&#x201D;&#x6253;&#x5F00;&#x201C;&#x547D;&#x4EE4;&#x9762;&#x677F;&#x201D;&#xFF0C;&#x8F93;&#x5165;&#x201C;go:Install/Update Tools&#x201D;&#xFF0C;&#x5168;&#x9009;&#x5E76;&#x201C;&#x786E;&#x5B9A;&#x201D;&#x5B89;&#x88C5;</p>
</blockquote>
<hr>
<h1 id="&#x8BED;&#x6CD5;"><a name="&#x8BED;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#&#x8BED;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x8BED;&#x6CD5;</h1>
<h2 id="&#x6570;&#x636E;&#x7C7B;&#x578B;"><a name="&#x6570;&#x636E;&#x7C7B;&#x578B;" class="anchor-navigation-ex-anchor" href="#&#x6570;&#x636E;&#x7C7B;&#x578B;"><i class="fa fa-link" aria-hidden="true"></i></a>2.1. &#x6570;&#x636E;&#x7C7B;&#x578B;</h2>
<p>&#x5E03;&#x5C14;&#x578B;&#xFF1A;bool</p>
<p>&#x6709;&#x7B26;&#x53F7;&#x6574;&#x578B;&#xFF1A;<br> int<br> int8&#xFF08;-128~127&#xFF09;<br> int16&#xFF08;-32768~32767&#xFF09;<br> int32&#xFF08;-2147483648~2147483647&#xFF09;<br> int64&#xFF08;-9223372036854775808~9223372036854775807&#xFF09;</p>
<p>&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x578B;&#xFF1A;<br> uint<br> uint8&#xFF08;0~255&#xFF09;<br> uint16&#xFF08;0~65535&#xFF09;<br> uint32&#xFF08;0~4294967295&#xFF09;<br> uint64&#xFF08;0~18446744073709551615&#xFF09;  </p>
<p>&#x6D6E;&#x70B9;&#x578B;&#xFF1A;float32&#x3001;float64&#x3001;complex64&#x3001;complex128</p>
<p>&#x5B57;&#x7B26;&#x4E32;&#x578B;&#xFF1A;string</p>
<p>&#x5176;&#x4ED6;&#xFF1A;byte&#x3001;rune&#x3001;uintptr&#xFF08;&#x65E0;&#x7B26;&#x53F7;&#x6574;&#x578B;&#xFF0C;&#x7528;&#x4E8E;&#x5B58;&#x653E;&#x4E00;&#x4E2A;&#x6307;&#x9488;&#xFF09;</p>
<h2 id="&#x5173;&#x952E;&#x5B57;"><a name="&#x5173;&#x952E;&#x5B57;" class="anchor-navigation-ex-anchor" href="#&#x5173;&#x952E;&#x5B57;"><i class="fa fa-link" aria-hidden="true"></i></a>2.2. &#x5173;&#x952E;&#x5B57;</h2>
<table class="table table-bordered table-striped table-condensed">
  <tr>
    <td>break</td>
    <td>default</td>
    <td>func</td>
    <td>interface</td>
    <td>select</td>
  </tr>
  <tr>
    <td>case</td>
    <td>defer</td>
    <td>go</td>
    <td>map</td>
    <td>struct</td>
  </tr>
  <tr>
    <td>chan</td>
    <td>else</td>
    <td>goto</td>
    <td>package</td>
    <td>switch</td>
  </tr>
  <tr>
    <td>const</td>
    <td>fallthrough</td>
    <td>if</td>
    <td>range</td>
    <td>type</td>
  </tr>
  <tr>
    <td>continue</td>
    <td>for</td>
    <td>import</td>
    <td>return</td>
    <td>var</td>
  </tr>
</table>

<p>&#x901A;&#x8FC7; <strong>const</strong> &#x5173;&#x952E;&#x5B57;&#x6765;&#x8FDB;&#x884C;&#x5E38;&#x91CF;&#x7684;&#x5B9A;&#x4E49;&#x3002;<br>&#x901A;&#x8FC7;&#x5728;&#x51FD;&#x6570;&#x4F53;&#x5916;&#x90E8;&#x4F7F;&#x7528; <strong>var</strong> &#x5173;&#x952E;&#x5B57;&#x6765;&#x8FDB;&#x884C;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x7684;&#x58F0;&#x660E;&#x548C;&#x8D4B;&#x503C;&#x3002;<br>&#x901A;&#x8FC7; <strong>type</strong> &#x5173;&#x952E;&#x5B57;&#x6765;&#x8FDB;&#x884C;&#x7ED3;&#x6784;&#xFF08;<strong>struct</strong>&#xFF09;&#x548C;&#x63A5;&#x53E3;&#xFF08;<strong>interface</strong>&#xFF09;&#x7684;&#x58F0;&#x660E;&#x3002;<br>&#x901A;&#x8FC7; <strong>func</strong> &#x5173;&#x952E;&#x5B57;&#x6765;&#x8FDB;&#x884C;&#x51FD;&#x6570;&#x7684;&#x58F0;&#x660E;&#x3002;  </p>
<p>&#x53EF;&#x89C1;&#x6027;&#x89C4;&#x5219;
Go&#x8BED;&#x8A00;&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;&#x5927;&#x5C0F;&#x5199;&#x6765;&#x51B3;&#x5B9A;&#x8BE5;&#x5E38;&#x91CF;&#x3001;&#x53D8;&#x91CF;&#x3001;&#x7C7B;&#x578B;&#x3001;&#x63A5;&#x53E3;&#x3001;&#x7ED3;&#x6784;&#x6216;&#x51FD;&#x6570;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x88AB;&#x5916;&#x90E8;&#x5305;&#x6240;&#x8C03;&#x7528;&#x3002;
&#x51FD;&#x6570;&#x540D;&#x9996;&#x5B57;&#x6BCD;&#x5C0F;&#x5199;&#x5373;&#x4E3A;private&#xFF0C;&#x51FD;&#x6570;&#x540D;&#x9996;&#x5B57;&#x6BCD;&#x5927;&#x5199;&#x5373;&#x4E3A;public&#x3002;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">getId</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token punctuation">{</span> <span class="token punctuation">}</span> <span class="token comment">// &#x79C1;&#x6709;</span>
<span class="token keyword">func</span> <span class="token function">Printf</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token punctuation">}</span> <span class="token comment">// &#x516C;&#x5171;</span>
</code></pre>
<h2 id="&#x53D8;&#x91CF;&#x58F0;&#x660E;"><a name="&#x53D8;&#x91CF;&#x58F0;&#x660E;" class="anchor-navigation-ex-anchor" href="#&#x53D8;&#x91CF;&#x58F0;&#x660E;"><i class="fa fa-link" aria-hidden="true"></i></a>2.3. &#x53D8;&#x91CF;&#x58F0;&#x660E;</h2>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x65B9;&#x5F0F;1</span>
<span class="token keyword">var</span> a <span class="token builtin">int</span>       <span class="token comment">// &#x4E0D;&#x521D;&#x59CB;&#x5316;&#x503C;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;&#xFF1A;0</span>
<span class="token keyword">var</span> a <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">123</span>   <span class="token comment">// &#x521D;&#x59CB;&#x5316;&#x503C;</span>

<span class="token comment">// &#x65B9;&#x5F0F;2&#xFF08;&#x65E0;&#x9700;&#x58F0;&#x660E;&#x7C7B;&#x578B;&#xFF0C;&#x6839;&#x636E;&#x521D;&#x59CB;&#x5316;&#x503C;&#x81EA;&#x52A8;&#x63A8;&#x65AD;&#xFF09;</span>
<span class="token keyword">var</span> a <span class="token operator">=</span> <span class="token number">123</span>

<span class="token comment">// &#x65B9;&#x5F0F;3&#xFF08;&#x65E0;&#x9700;var&#x548C;&#x58F0;&#x660E;&#x7C7B;&#x578B;&#xFF0C;&#x6839;&#x636E;&#x521D;&#x59CB;&#x5316;&#x503C;&#x81EA;&#x52A8;&#x63A8;&#x65AD;&#xFF0C;&#x4E0D;&#x652F;&#x6301;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#xFF09;</span>
a <span class="token operator">:=</span> <span class="token number">123</span>

<span class="token comment">// &#x65B9;&#x5F0F;4&#xFF08;&#x591A;&#x53D8;&#x91CF;&#x58F0;&#x660E;&#xFF09;</span>
<span class="token keyword">var</span> a<span class="token punctuation">,</span> b <span class="token operator">=</span> <span class="token number">123</span><span class="token punctuation">,</span> <span class="token string">&quot;abc&quot;</span>     <span class="token comment">// &#x81EA;&#x52A8;&#x63A8;&#x65AD;&#x7C7B;&#x578B;</span>
<span class="token keyword">var</span> a<span class="token punctuation">,</span> b <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">123</span><span class="token punctuation">,</span> <span class="token number">456</span>   <span class="token comment">// &#x7C7B;&#x578B;&#x76F8;&#x540C;&#x7684;&#x53C2;&#x6570;</span>

<span class="token keyword">var</span> <span class="token punctuation">{</span>
  a <span class="token builtin">int</span> <span class="token operator">=</span> <span class="token number">123</span>
  b <span class="token builtin">string</span> <span class="token operator">=</span> <span class="token string">&quot;abc&quot;</span>
<span class="token punctuation">}</span>

<span class="token keyword">var</span> <span class="token punctuation">{</span>
  a <span class="token operator">=</span> <span class="token number">123</span>
  b <span class="token operator">=</span> <span class="token string">&quot;abc&quot;</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="const&#x5E38;&#x91CF;&#x548C;iota&#x5B9E;&#x73B0;&#x679A;&#x4E3E;&#x6570;&#x503C;"><a name="const&#x5E38;&#x91CF;&#x548C;iota&#x5B9E;&#x73B0;&#x679A;&#x4E3E;&#x6570;&#x503C;" class="anchor-navigation-ex-anchor" href="#const&#x5E38;&#x91CF;&#x548C;iota&#x5B9E;&#x73B0;&#x679A;&#x4E3E;&#x6570;&#x503C;"><i class="fa fa-link" aria-hidden="true"></i></a>2.4. const&#x5E38;&#x91CF;&#x548C;iota&#x5B9E;&#x73B0;&#x679A;&#x4E3E;&#x6570;&#x503C;</h2>
<blockquote>
<p>iota &#x5FC5;&#x987B;&#x8DDF;&#x968F;const&#x4F7F;&#x7528;</p>
</blockquote>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x548C;&#x53D8;&#x91CF;&#x7C7B;&#x4F3C;&#xFF0C;&#x7528;const&#x4EE3;&#x66FF;var&#x58F0;&#x660E;&#x53D8;&#x91CF;</span>
<span class="token keyword">const</span> a <span class="token operator">=</span> <span class="token number">123</span>

<span class="token comment">// &#x901A;&#x8FC7;const&#x6765;&#x5B9E;&#x73B0;&#x679A;&#x4E3E;</span>
<span class="token keyword">const</span> <span class="token punctuation">(</span>
  BeiJing   <span class="token operator">=</span> <span class="token number">0</span>
  ShangHai  <span class="token operator">=</span> <span class="token number">1</span>
  GuangZhou <span class="token operator">=</span> <span class="token number">2</span>
<span class="token punctuation">)</span>

<span class="token comment">// &#x901A;&#x8FC7;const&#x548C;iota&#x6765;&#x5B9E;&#x73B0;&#x679A;&#x4E3E;&#x503C;&#x81EA;&#x52A8;&#x7D2F;&#x52A0;&#xFF0C;&#x9996;&#x884C;iota&#x9ED8;&#x8BA4;&#x4E3A;&#x96F6;&#xFF0C;&#x540E;&#x7EED;&#x9010;&#x884C;+1</span>
<span class="token keyword">const</span> <span class="token punctuation">(</span>
  BeiJing   <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token comment">// iota=0,</span>
  ShangHai         <span class="token comment">// iota=1</span>
  GuangZhou        <span class="token comment">// iota=2</span>
<span class="token punctuation">)</span>

<span class="token comment">// &#x5947;&#x8469;&#x7528;&#x6CD5;</span>
<span class="token keyword">const</span> <span class="token punctuation">(</span>
  g<span class="token punctuation">,</span> h <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token boolean">iota</span> <span class="token operator">+</span> <span class="token number">2</span> <span class="token comment">// iota=0, g=iota+1=1, h=iota+2=2</span>
  i<span class="token punctuation">,</span> j                      <span class="token comment">// iota=1, i=iota+1=2, j=iota+2=3</span>
  k<span class="token punctuation">,</span> l                      <span class="token comment">// iota=2, i=iota+1=3, j=iota+2=4</span>

  m<span class="token punctuation">,</span> n <span class="token operator">=</span> <span class="token boolean">iota</span> <span class="token operator">*</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token boolean">iota</span> <span class="token operator">*</span> <span class="token number">3</span> <span class="token comment">// iota=3, i=iota*2=6, j=iota*3=9</span>
  o<span class="token punctuation">,</span> p                      <span class="token comment">// iota=4, i=iota*2=8, j=iota*3=12</span>
<span class="token punctuation">)</span>
</code></pre>
<h2 id="&#x51FD;&#x6570;"><a name="&#x51FD;&#x6570;" class="anchor-navigation-ex-anchor" href="#&#x51FD;&#x6570;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5. &#x51FD;&#x6570;</h2>
<h3 id="&#x4F20;&#x53C2;&#x3001;&#x8FD4;&#x56DE;"><a name="&#x4F20;&#x53C2;&#x3001;&#x8FD4;&#x56DE;" class="anchor-navigation-ex-anchor" href="#&#x4F20;&#x53C2;&#x3001;&#x8FD4;&#x56DE;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5.1. &#x4F20;&#x53C2;&#x3001;&#x8FD4;&#x56DE;</h3>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  ret0 <span class="token operator">:=</span> <span class="token function">Method_1</span><span class="token punctuation">(</span><span class="token string">&quot;yzq&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;18&quot;</span><span class="token punctuation">)</span>
  ret1<span class="token punctuation">,</span> ret2 <span class="token operator">:=</span> <span class="token function">Method_2</span><span class="token punctuation">(</span><span class="token string">&quot;yzq&quot;</span><span class="token punctuation">,</span> <span class="token number">18</span><span class="token punctuation">)</span>
  ret3<span class="token punctuation">,</span> ret4 <span class="token operator">:=</span> <span class="token function">Method_3</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;ret0 =&quot;</span><span class="token punctuation">,</span> ret0<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;ret1 =&quot;</span><span class="token punctuation">,</span> ret1<span class="token punctuation">,</span> <span class="token string">&quot;ret2 =&quot;</span><span class="token punctuation">,</span> ret2<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;ret3 =&quot;</span><span class="token punctuation">,</span> ret3<span class="token punctuation">,</span> <span class="token string">&quot;ret4 =&quot;</span><span class="token punctuation">,</span> ret4<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x540C;&#x7C7B;&#x578B;&#x5F62;&#x53C2;&#xFF0C;&#x5355;&#x4E00;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">Method_1</span><span class="token punctuation">(</span>name<span class="token punctuation">,</span> age <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>age<span class="token punctuation">,</span> <span class="token string">&quot;&#x5C81;&#x7684;&quot;</span><span class="token punctuation">,</span> name<span class="token punctuation">,</span> <span class="token string">&quot;&#x4F60;&#x597D;&quot;</span><span class="token punctuation">)</span>
  <span class="token keyword">return</span> <span class="token string">&quot;aaa&quot;</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x4E0D;&#x540C;&#x7C7B;&#x578B;&#x5F62;&#x53C2;&#xFF0C;&#x591A;&#x4E2A;&#x533F;&#x540D;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x7C7B;&#x4F3C;DotNet Tuple&#x5143;&#x7956;</span>
<span class="token keyword">func</span> <span class="token function">Method_2</span><span class="token punctuation">(</span>name <span class="token builtin">string</span><span class="token punctuation">,</span> age <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>age<span class="token punctuation">,</span> <span class="token string">&quot;&#x5C81;&#x7684;&quot;</span><span class="token punctuation">,</span> name<span class="token punctuation">,</span> <span class="token string">&quot;&#x4F60;&#x597D;&quot;</span><span class="token punctuation">)</span>
  <span class="token keyword">return</span> <span class="token string">&quot;bbb&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;ccc&quot;</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x65E0;&#x5F62;&#x53C2;&#xFF0C;&#x591A;&#x4E2A;&#x547D;&#x540D;&#x8FD4;&#x56DE;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">Method_3</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>ret3 <span class="token builtin">string</span><span class="token punctuation">,</span> ret4 <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">//func Method_3() (ret3, ret4 string) { // &#x540C;&#x7C7B;&#x578B;&#x53C2;&#x6570;&#x5408;&#x5E76;&#x58F0;&#x660E;</span>
  ret3 <span class="token operator">=</span> <span class="token string">&quot;ddd&quot;</span>
  ret4 <span class="token operator">=</span> <span class="token string">&quot;eee&quot;</span>
  <span class="token keyword">return</span>
<span class="token punctuation">}</span>

<span class="token comment">// 18 &#x5C81;&#x7684; yzq &#x4F60;&#x597D;</span>
<span class="token comment">// 18 &#x5C81;&#x7684; yzq &#x4F60;&#x597D;</span>
<span class="token comment">// ret0 = aaa</span>
<span class="token comment">// ret1 = bbb ret2 = ccc</span>
<span class="token comment">// ret3 = ddd ret4 = eee</span>
</code></pre>
<h3 id="&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;"><a name="&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;" class="anchor-navigation-ex-anchor" href="#&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5.2. &#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;</h3>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x58F0;&#x660E;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x7C7B;&#x578B;</span>
<span class="token keyword">type</span> cb <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">int</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">testCallBack</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> callBack<span class="token punctuation">)</span>
  <span class="token function">testCallBack</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token keyword">func</span><span class="token punctuation">(</span>x <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span>
    fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6211;&#x662F;&#x56DE;&#x8C03;&#xFF0C;x&#xFF1A;%d\n&quot;</span><span class="token punctuation">,</span> x<span class="token punctuation">)</span>
    <span class="token keyword">return</span> x
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">testCallBack</span><span class="token punctuation">(</span>x <span class="token builtin">int</span><span class="token punctuation">,</span> f cb<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token function">f</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">callBack</span><span class="token punctuation">(</span>x <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6211;&#x662F;&#x56DE;&#x8C03;&#xFF0C;x&#xFF1A;%d\n&quot;</span><span class="token punctuation">,</span> x<span class="token punctuation">)</span>
  <span class="token keyword">return</span> x
<span class="token punctuation">}</span>

<span class="token comment">// &#x6211;&#x662F;&#x56DE;&#x8C03;&#xFF0C;x&#xFF1A;1</span>
<span class="token comment">// &#x6211;&#x662F;&#x56DE;&#x8C03;&#xFF0C;x&#xFF1A;2</span>
</code></pre>
<h3 id="&#x95ED;&#x5305;"><a name="&#x95ED;&#x5305;" class="anchor-navigation-ex-anchor" href="#&#x95ED;&#x5305;"><i class="fa fa-link" aria-hidden="true"></i></a>2.5.3. &#x95ED;&#x5305;</h3>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x5B9A;&#x4E49;&#x51FD;&#x6570;getSequence()&#x8FD4;&#x56DE;&#x503C;&#x662F;&#x533F;&#x540D;&#x51FD;&#x6570;func()&#xFF0C;&#x8BE5;&#x533F;&#x540D;&#x51FD;&#x6570;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x662F;int</span>
<span class="token keyword">func</span> <span class="token function">getSequence</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span>
  i <span class="token operator">:=</span> <span class="token number">0</span>
  <span class="token keyword">return</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">int</span> <span class="token punctuation">{</span>
    i <span class="token operator">+=</span> <span class="token number">1</span>
    <span class="token keyword">return</span> i
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">/* nextNumber &#x4E3A;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x51FD;&#x6570; i &#x4E3A; 0 */</span>
  nextNumber <span class="token operator">:=</span> <span class="token function">getSequence</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

  <span class="token comment">/* &#x8C03;&#x7528; nextNumber &#x51FD;&#x6570;&#xFF0C;i &#x53D8;&#x91CF;&#x81EA;&#x589E; 1 &#x5E76;&#x8FD4;&#x56DE; */</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">nextNumber</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">nextNumber</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">nextNumber</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>

  <span class="token comment">/* &#x521B;&#x5EFA;&#x65B0;&#x7684;&#x51FD;&#x6570; nextNumber1&#xFF0C;&#x5E76;&#x67E5;&#x770B;&#x7ED3;&#x679C; */</span>
  nextNumber1 <span class="token operator">:=</span> <span class="token function">getSequence</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">nextNumber1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">nextNumber1</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
s
<span class="token comment">// 1</span>
<span class="token comment">// 2</span>
<span class="token comment">// 3</span>
<span class="token comment">// 1</span>
<span class="token comment">// 2</span>
</code></pre>
<blockquote>
<p>&#x95ED;&#x5305;&#x793A;&#x4F8B;</p>
</blockquote>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x95ED;&#x5305;&#x4F7F;&#x7528;&#x65B9;&#x6CD5;&#xFF0C;&#x51FD;&#x6570;&#x58F0;&#x660E;&#x4E2D;&#x7684;&#x8FD4;&#x56DE;&#x503C;(&#x95ED;&#x5305;&#x51FD;&#x6570;)&#x4E0D;&#x7528;&#x5199;&#x5177;&#x4F53;&#x7684;&#x5F62;&#x53C2;&#x540D;&#x79F0;</span>
<span class="token keyword">func</span> <span class="token function">add</span><span class="token punctuation">(</span>x1<span class="token punctuation">,</span> x2 <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token keyword">func</span><span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">,</span> <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">,</span> <span class="token builtin">int</span><span class="token punctuation">,</span> <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  i <span class="token operator">:=</span> <span class="token number">0</span>
  <span class="token keyword">return</span> <span class="token keyword">func</span><span class="token punctuation">(</span>x3<span class="token punctuation">,</span> x4 <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">(</span><span class="token builtin">int</span><span class="token punctuation">,</span> <span class="token builtin">int</span><span class="token punctuation">,</span> <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    i <span class="token operator">+=</span> <span class="token number">1</span>
    <span class="token keyword">return</span> i<span class="token punctuation">,</span> x1 <span class="token operator">+</span> x2<span class="token punctuation">,</span> x3 <span class="token operator">+</span> x4
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  add_func <span class="token operator">:=</span> <span class="token function">add</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">add_func</span><span class="token punctuation">(</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">add_func</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token function">add_func</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">//1 3 9</span>
<span class="token comment">//2 3 4</span>
<span class="token comment">//3 3 4</span>
</code></pre>
<h2 id="import&#x5305;&#x548C;init&#x65B9;&#x6CD5;"><a name="import&#x5305;&#x548C;init&#x65B9;&#x6CD5;" class="anchor-navigation-ex-anchor" href="#import&#x5305;&#x548C;init&#x65B9;&#x6CD5;"><i class="fa fa-link" aria-hidden="true"></i></a>2.6. import&#x5305;&#x548C;init&#x65B9;&#x6CD5;</h2>
<pre class="language-"><code class="lang-go"><span class="token keyword">package</span> Lib1

<span class="token keyword">import</span> <span class="token string">&quot;fmt&quot;</span>

<span class="token keyword">func</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6267;&#x884C; Lib1.init()&quot;</span><span class="token punctuation">)</span> <span class="token comment">// init&#x65B9;&#x6CD5;&#x5728;&#x8C03;&#x7528;&#x65B9;import&#x65F6;&#x6267;&#x884C;&#xFF0C;&#x53C2;&#x8003;DotNet&#x6784;&#x9020;&#x51FD;&#x6570;</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">Method</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6267;&#x884C; Lib1.Method()&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class="language-"><code class="lang-go"><span class="token keyword">package</span> Lib2

<span class="token keyword">import</span> <span class="token string">&quot;fmt&quot;</span>

<span class="token keyword">func</span> <span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6267;&#x884C; Lib2.init()&quot;</span><span class="token punctuation">)</span> <span class="token comment">// init&#x65B9;&#x6CD5;&#x5728;&#x8C03;&#x7528;&#x65B9;import&#x65F6;&#x6267;&#x884C;&#xFF0C;&#x53C2;&#x8003;DotNet&#x6784;&#x9020;&#x51FD;&#x6570;</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">Method</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x6267;&#x884C; Lib2.Method()&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre>
<pre class="language-"><code class="lang-go"><span class="token keyword">package</span> main

<span class="token comment">// &#x5BFC;&#x5165;Lib1&#xFF0C;&#x5E76;&#x58F0;&#x540D;&#x4E3A;MyLib&#xFF0C;&#x540E;&#x7EED;&#x901A;&#x8FC7;MyLib.Method()&#x8FDB;&#x884C;&#x8C03;&#x7528;</span>
<span class="token comment">// import &quot;HelloGo/TestImport/Lib1&quot; MyLib</span>

<span class="token keyword">import</span> <span class="token punctuation">(</span>
  <span class="token string">&quot;HelloGo/TestImport/Lib1&quot;</span> <span class="token comment">// &#x5BFC;&#x5165;Lib1&#xFF08;&#x6E90;&#x7801;&#x6839;&#x76EE;&#x5F55;&#x4E3A;%GOPATH%&#xFF0C;HelloGo&#x4E3A;&#x9879;&#x76EE;&#x6587;&#x4EF6;&#x5939;&#xFF09;</span>
  <span class="token string">&quot;HelloGo/TestImport/Lib2&quot;</span> <span class="token comment">// &#x5BFC;&#x5165;Lib2&#xFF08;&#x6E90;&#x7801;&#x6839;&#x76EE;&#x5F55;&#x4E3A;%GOPATH%&#xFF0C;HelloGo&#x4E3A;&#x9879;&#x76EE;&#x6587;&#x4EF6;&#x5939;&#xFF09;</span>

  <span class="token boolean">_</span> <span class="token string">&quot;HelloGo/TestImport/Lib1&quot;</span> <span class="token comment">// &#x5BFC;&#x5165;Lib1&#xFF0C;&#x4EC5;&#x5728;import&#x65F6;&#x6267;&#x884C;init&#x51FD;&#x6570;&#xFF0C;&#x65E0;&#x6CD5;&#x8C03;&#x7528;&#x5305;&#x5185;&#x51FD;&#x6570;</span>
  <span class="token punctuation">.</span> <span class="token string">&quot;HelloGo/TestImport/Lib1&quot;</span> <span class="token comment">// &#x5BFC;&#x5165;Lib1&#xFF0C;&#x5408;&#x5E76;&#x5F53;&#x524D;&#x5305;&#xFF0C;&#x540E;&#x7EED;&#x8C03;&#x7528;&#x7701;&#x7565;&#x5305;&#x540D;</span>
  MyLib <span class="token string">&quot;HelloGo/TestImport/Lib1&quot;</span> <span class="token comment">// &#x5BFC;&#x5165;Lib1&#xFF0C;&#x5E76;&#x58F0;&#x540D;&#x4E3A;MyLib&#xFF0C;&#x540E;&#x7EED;&#x901A;&#x8FC7;MyLib.Method()&#x8FDB;&#x884C;&#x8C03;&#x7528;</span>
<span class="token punctuation">)</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  Lib1<span class="token punctuation">.</span><span class="token function">Method</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// &#x8C03;&#x7528;Lib1.Method()</span>
  Lib2<span class="token punctuation">.</span><span class="token function">Method</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// &#x8C03;&#x7528;Lib2.Method()</span>
<span class="token punctuation">}</span>
</code></pre>
<h2 id="&#x6307;&#x9488;"><a name="&#x6307;&#x9488;" class="anchor-navigation-ex-anchor" href="#&#x6307;&#x9488;"><i class="fa fa-link" aria-hidden="true"></i></a>2.7. &#x6307;&#x9488;</h2>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  a <span class="token operator">:=</span> <span class="token number">1</span>
  <span class="token function">sub_1</span><span class="token punctuation">(</span>a<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main.a =&quot;</span><span class="token punctuation">,</span> a<span class="token punctuation">)</span> <span class="token comment">// main.a == 1</span>

  b <span class="token operator">:=</span> <span class="token number">1</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main.&amp;b =&quot;</span><span class="token punctuation">,</span> <span class="token operator">&amp;</span>b<span class="token punctuation">)</span> <span class="token comment">// main.&amp;b == 0xc000016098&#xFF08;&amp;b&#x4E3A;&#x53C2;&#x6570;b&#x7684;&#x5730;&#x5740;&#xFF09;</span>
  <span class="token function">sub_2</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>b<span class="token punctuation">)</span>                    <span class="token comment">// &#x4F20;&#x9012;&#x53C2;&#x6570;b&#x7684;&#x5730;&#x5740;</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main.b =&quot;</span><span class="token punctuation">,</span> b<span class="token punctuation">)</span>   <span class="token comment">// main.b == 3</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x53C2;&#x6570;&#x4F20;&#x503C;&#xFF0C;&#x5728;&#x5B50;&#x51FD;&#x6570;&#x5185;&#x6539;&#x53D8;&#xFF0C;&#x4E0D;&#x5F71;&#x54CD;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">sub_1</span><span class="token punctuation">(</span>a <span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  a <span class="token operator">=</span> <span class="token number">2</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;sub_1.a =&quot;</span><span class="token punctuation">,</span> a<span class="token punctuation">)</span> <span class="token comment">// sub_1.a == 2</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x53C2;&#x6570;&#x4F20;&#x5740;&#xFF0C;&#x5728;&#x5B50;&#x51FD;&#x6570;&#x5185;&#x6539;&#x53D8;&#xFF0C;&#x5F71;&#x54CD;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">sub_2</span><span class="token punctuation">(</span>b <span class="token operator">*</span><span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token comment">// &#x6B64;&#x5904;b&#x4E3A;&#x53C2;&#x6570;b&#x7684;&#x5730;&#x5740;</span>
  <span class="token operator">*</span>b <span class="token operator">=</span> <span class="token number">3</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;sub_2.*b =&quot;</span><span class="token punctuation">,</span> <span class="token operator">*</span>b<span class="token punctuation">)</span> <span class="token comment">// sub_2.*b == 3&#xFF08;*b&#x83B7;&#x53D6;&#x53C2;&#x6570;b&#x7684;&#x503C;&#xFF09;</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;sub_2.b =&quot;</span><span class="token punctuation">,</span> b<span class="token punctuation">)</span>   <span class="token comment">// sub_2.b == 0xc000016098</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x8F93;&#x51FA;&#xFF1A;</span>
<span class="token comment">// sub_1.a = 2</span>
<span class="token comment">// main.a = 1</span>
<span class="token comment">// main.&amp;b = 0xc000016098</span>
<span class="token comment">// sub_2.*b = 3</span>
<span class="token comment">// sub_2.b = 0xc000016098</span>
<span class="token comment">// main.b = 3</span>
</code></pre>
<p>&#x4F20;&#x5740;&#x65B9;&#x5F0F;&#xFF0C;&#x4EA4;&#x6362;&#x53D8;&#x91CF;&#x503C;&#xFF0C;&#x793A;&#x4F8B;&#xFF1A;</p>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  a <span class="token operator">:=</span> <span class="token number">1</span>
  b <span class="token operator">:=</span> <span class="token number">2</span>

  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main.a =&quot;</span><span class="token punctuation">,</span> a<span class="token punctuation">,</span> <span class="token string">&quot;main.b =&quot;</span><span class="token punctuation">,</span> b<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main.&amp;a =&quot;</span><span class="token punctuation">,</span> <span class="token operator">&amp;</span>a<span class="token punctuation">,</span> <span class="token string">&quot;main.&amp;b =&quot;</span><span class="token punctuation">,</span> <span class="token operator">&amp;</span>b<span class="token punctuation">)</span>
  <span class="token function">swap</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>a<span class="token punctuation">,</span> <span class="token operator">&amp;</span>b<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main.a =&quot;</span><span class="token punctuation">,</span> a<span class="token punctuation">,</span> <span class="token string">&quot;main.b =&quot;</span><span class="token punctuation">,</span> b<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main.&amp;a =&quot;</span><span class="token punctuation">,</span> <span class="token operator">&amp;</span>a<span class="token punctuation">,</span> <span class="token string">&quot;main.&amp;b =&quot;</span><span class="token punctuation">,</span> <span class="token operator">&amp;</span>b<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x4EA4;&#x6362;&#x6362;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">swap</span><span class="token punctuation">(</span>a <span class="token operator">*</span><span class="token builtin">int</span><span class="token punctuation">,</span> b <span class="token operator">*</span><span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;swap.*a =&quot;</span><span class="token punctuation">,</span> <span class="token operator">*</span>a<span class="token punctuation">,</span> <span class="token string">&quot;swap.*b =&quot;</span><span class="token punctuation">,</span> <span class="token operator">*</span>b<span class="token punctuation">)</span>

  tmp <span class="token operator">:=</span> <span class="token operator">*</span>a
  <span class="token operator">*</span>a <span class="token operator">=</span> <span class="token operator">*</span>b
  <span class="token operator">*</span>b <span class="token operator">=</span> tmp
<span class="token punctuation">}</span>

<span class="token comment">// &#x8F93;&#x51FA;&#xFF1A;</span>
<span class="token comment">// main.a = 1 main.b = 2</span>
<span class="token comment">// main.&amp;a = 0xc000016098 main.&amp;b = 0xc0000160b0</span>
<span class="token comment">// swap.*a = 1 swap.*b = 2</span>
<span class="token comment">// main.a = 2 main.b = 1</span>
<span class="token comment">// main.&amp;a = 0xc000016098 main.&amp;b = 0xc0000160b0</span>
</code></pre>
<h2 id="defer-&#x5EF6;&#x540E;&#x6267;&#x884C;"><a name="defer-&#x5EF6;&#x540E;&#x6267;&#x884C;" class="anchor-navigation-ex-anchor" href="#defer-&#x5EF6;&#x540E;&#x6267;&#x884C;"><i class="fa fa-link" aria-hidden="true"></i></a>2.8. defer &#x5EF6;&#x540E;&#x6267;&#x884C;</h2>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// defer&#x5728;&#x8C03;&#x7528;&#x51FD;&#x6570;&#x6267;&#x884C;&#x5B8C;&#xFF08;return&#x540E;&#xFF09;&#xFF0C;&#x6808;&#x5F0F;&#x5904;&#x7406;&#x5F53;&#x524D;&#x51FD;&#x6570;&#x5185;&#x5B9A;&#x4E49;&#x7684;&#x6BCF;&#x4E2A;defer&#x5BF9;&#x8C61;&#xFF08;&#x540E;&#x8FDB;&#x5148;&#x51FA;&#xFF09;</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main begin&quot;</span><span class="token punctuation">)</span>
  <span class="token keyword">defer</span> <span class="token function">fun_1</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment">// &#x5EF6;&#x540E;&#x51FD;&#x6570;fun_1&#x8FDB;&#x6808;</span>
  <span class="token keyword">defer</span> <span class="token function">fun_2</span><span class="token punctuation">(</span><span class="token punctuation">)</span>     <span class="token comment">// &#x5EF6;&#x540E;&#x51FD;&#x6570;fun_2&#x8FDB;&#x6808;</span>
  result <span class="token operator">:=</span> <span class="token function">fun_3</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// &#x540C;&#x6B65;&#x6267;&#x884C;&#x51FD;&#x6570;fun_3</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;fun_3 =&quot;</span><span class="token punctuation">,</span> result<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;main end&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">fun_1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;fun_1 run&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">fun_2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;fun_2 run&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">fun_3</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;fun_3 run&quot;</span><span class="token punctuation">)</span>
  <span class="token keyword">defer</span> <span class="token function">fun_3_1</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment">// &#x5EF6;&#x540E;&#x51FD;&#x6570;fun_3_1&#x8FDB;&#x6808;</span>
  <span class="token keyword">return</span> <span class="token function">fun_3_2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// &#x540C;&#x6B65;&#x6267;&#x884C;&#x51FD;&#x6570;fun_3_2&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">fun_3_1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;fun_3_1 run&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">fun_3_2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">bool</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;fun_3_2 run&quot;</span><span class="token punctuation">)</span>
  <span class="token keyword">return</span> <span class="token boolean">true</span>
<span class="token punctuation">}</span>

<span class="token comment">// main begin</span>
<span class="token comment">// fun_3 run</span>
<span class="token comment">// fun_3_2 run</span>
<span class="token comment">// fun_3_1 run</span>
<span class="token comment">// fun_3 = true</span>
<span class="token comment">// main end</span>
<span class="token comment">// fun_2 run</span>
<span class="token comment">// fun_1 run</span>
</code></pre>
<h2 id="&#x5B9A;&#x957F;&#x6570;&#x7EC4;"><a name="&#x5B9A;&#x957F;&#x6570;&#x7EC4;" class="anchor-navigation-ex-anchor" href="#&#x5B9A;&#x957F;&#x6570;&#x7EC4;"><i class="fa fa-link" aria-hidden="true"></i></a>2.9. &#x5B9A;&#x957F;&#x6570;&#x7EC4;</h2>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> arrLen <span class="token operator">=</span> <span class="token number">3</span>      <span class="token comment">// &#x6570;&#x7EC4;&#x957F;&#x5EA6;&#x53EA;&#x80FD;&#x662F;const&#x4E0D;&#x80FD;&#x662F;val</span>
  <span class="token keyword">var</span> arr_1 <span class="token punctuation">[</span>arrLen<span class="token punctuation">]</span><span class="token builtin">int</span> <span class="token comment">// &#x5B9A;&#x957F;&#x6570;&#x7EC4;</span>
  <span class="token comment">// var arr_2 = [arrLen]int{10, 20, 30}  // &#x5B9A;&#x957F;&#x6570;&#x7EC4;&#xFF08;&#x521D;&#x59CB;&#x5316;&#x90E8;&#x5206;&#x503C;&#xFF09;</span>
  <span class="token comment">//arr_2 := [arrLen + 1]int{10, 20, 30} // &#x5B9A;&#x957F;&#x6570;&#x7EC4;&#xFF08;&#x521D;&#x59CB;&#x5316;&#x90E8;&#x5206;&#x503C;&#xFF09;</span>
  arr_2 <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token operator">...</span><span class="token punctuation">]</span><span class="token builtin">int</span><span class="token punctuation">{</span><span class="token number">10</span><span class="token punctuation">,</span> <span class="token number">20</span><span class="token punctuation">,</span> <span class="token number">30</span><span class="token punctuation">,</span> <span class="token number">0</span><span class="token punctuation">}</span> <span class="token comment">// &#x5B9A;&#x957F;&#x6570;&#x7EC4;&#xFF08;&#x521D;&#x59CB;&#x5316;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#x5168;&#x90E8;&#x503C;&#xFF0C;&#x53EF;&#x7528;...&#x4EE3;&#x66FF;&#x957F;&#x5EA6;&#x503C;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x957F;&#x5EA6;&#x4E3A;&#x6570;&#x7EC4;&#x5B9E;&#x9645;&#x957F;&#x5EA6;&#xFF09;</span>

  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_1 Type:%T\n&quot;</span><span class="token punctuation">,</span> arr_1<span class="token punctuation">)</span> <span class="token comment">// &#x7C7B;&#x578B;&#x4E3A;&#x957F;&#x5EA6;&#x662F;3&#x7684;int&#x6570;&#x7EC4;</span>
  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_2 Type:%T\n&quot;</span><span class="token punctuation">,</span> arr_2<span class="token punctuation">)</span> <span class="token comment">// &#x7C7B;&#x578B;&#x4E3A;&#x957F;&#x5EA6;&#x662F;4&#x7684;int&#x6570;&#x7EC4;&#xFF08;&#x957F;&#x5EA6;&#x4E0D;&#x540C;&#x89C6;&#x4E3A;&#x4E0D;&#x540C;&#x7C7B;&#x578B;&#xFF0C;&#x51FD;&#x6570;&#x4F20;&#x53C2;&#x533A;&#x5206;&#x957F;&#x5EA6;&#xFF09;</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;-------------&quot;</span><span class="token punctuation">)</span>

  <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> arrLen<span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">{</span>
    fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_1[%v] = %v\n&quot;</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> arr_1<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;-------------&quot;</span><span class="token punctuation">)</span>

  <span class="token keyword">for</span> i <span class="token operator">:=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> <span class="token function">len</span><span class="token punctuation">(</span>arr_2<span class="token punctuation">)</span><span class="token punctuation">;</span> i<span class="token operator">++</span> <span class="token punctuation">{</span> <span class="token comment">// &#x5FAA;&#x73AF;&#x65B9;&#x5F0F;&#x4E00;</span>
    fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_2[%v] = %v\n&quot;</span><span class="token punctuation">,</span> i<span class="token punctuation">,</span> arr_2<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;-------------&quot;</span><span class="token punctuation">)</span>

  <span class="token keyword">for</span> index<span class="token punctuation">,</span> item <span class="token operator">:=</span> <span class="token keyword">range</span> arr_2 <span class="token punctuation">{</span> <span class="token comment">// &#x5FAA;&#x73AF;&#x65B9;&#x5F0F;&#x4E8C;range&#xFF08;index&#xFF1A;&#x4E0B;&#x6807;&#xFF0C;item&#xFF1A;&#x9879;&#xFF09;</span>
    fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_2[%v] = %v\n&quot;</span><span class="token punctuation">,</span> index<span class="token punctuation">,</span> item<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;-------------&quot;</span><span class="token punctuation">)</span>

  <span class="token comment">// Foreach(arr_1) // &#x6B64;&#x4F20;&#x503C;&#x4F1A;&#x62A5;&#x9519;&#xFF0C;[3]int&#x548C;[4]int&#x4E3A;&#x4E0D;&#x540C;&#x7C7B;&#x578B;</span>
  <span class="token function">Foreach</span><span class="token punctuation">(</span>arr_2<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9A;&#x957F;&#x6570;&#x7EC4;&#x4E3A;&#x4F20;&#x503C;&#xFF08;&#x5F62;&#x53C2;&#x9700;&#x6307;&#x5B9A;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#xFF09;&#xFF0C;&#x5728;&#x5B50;&#x51FD;&#x6570;&#x5185;&#x6539;&#x53D8;&#xFF0C;&#x4E0D;&#x5F71;&#x54CD;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">Foreach</span><span class="token punctuation">(</span>arr <span class="token punctuation">[</span><span class="token number">4</span><span class="token punctuation">]</span><span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> item <span class="token operator">:=</span> <span class="token keyword">range</span> arr <span class="token punctuation">{</span> <span class="token comment">// forr</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// arr_1 Type:[3]int</span>
<span class="token comment">// arr_2 Type:[4]int</span>
<span class="token comment">// -------------</span>
<span class="token comment">// arr_1[0] = 0</span>
<span class="token comment">// arr_1[1] = 0</span>
<span class="token comment">// arr_1[2] = 0</span>
<span class="token comment">// -------------</span>
<span class="token comment">// arr_2[0] = 10</span>
<span class="token comment">// arr_2[1] = 20</span>
<span class="token comment">// arr_2[2] = 30</span>
<span class="token comment">// arr_2[3] = 0</span>
<span class="token comment">// -------------</span>
<span class="token comment">// arr_2[0] = 10</span>
<span class="token comment">// arr_2[1] = 20</span>
<span class="token comment">// arr_2[2] = 30</span>
<span class="token comment">// arr_2[3] = 0</span>
<span class="token comment">// -------------</span>
<span class="token comment">// 10</span>
<span class="token comment">// 20</span>
<span class="token comment">// 30</span>
<span class="token comment">// 0</span>
</code></pre>
<h2 id="slice&#xFF08;&#x5207;&#x7247;&#x3001;&#x52A8;&#x6001;&#x6570;&#x7EC4;&#xFF09;"><a name="slice&#xFF08;&#x5207;&#x7247;&#x3001;&#x52A8;&#x6001;&#x6570;&#x7EC4;&#xFF09;" class="anchor-navigation-ex-anchor" href="#slice&#xFF08;&#x5207;&#x7247;&#x3001;&#x52A8;&#x6001;&#x6570;&#x7EC4;&#xFF09;"><i class="fa fa-link" aria-hidden="true"></i></a>2.10. slice&#xFF08;&#x5207;&#x7247;&#x3001;&#x52A8;&#x6001;&#x6570;&#x7EC4;&#xFF09;</h2>
<pre class="language-"><code class="lang-go"><span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// make(&#x5207;&#x7247;&#x7C7B;&#x578B;, &#x5207;&#x7247;&#x521D;&#x59CB;&#x5316;&#x957F;&#x5EA6;, &#x5207;&#x7247;&#x5BB9;&#x91CF;)</span>
  arr_1 <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">int</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">6</span><span class="token punctuation">)</span>    <span class="token comment">// &#x5B9A;&#x4E49;&#x65B9;&#x5F0F;&#x4E00;&#xFF1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6574;&#x578B;&#x5207;&#x7247;&#xFF0C;&#x5176;&#x521D;&#x59CB;&#x5316;&#x957F;&#x5EA6;&#x4E3A;3&#xFF0C;&#x5BB9;&#x91CF;&#x4E3A;6</span>
  arr_2 <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">int</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span>       <span class="token comment">// &#x5B9A;&#x4E49;&#x65B9;&#x5F0F;&#x4E8C;&#xFF1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6574;&#x578B;&#x5207;&#x7247;&#xFF0C;&#x5176;&#x521D;&#x59CB;&#x5316;&#x957F;&#x5EA6;&#x4E3A;4&#x3002;&#x82E5;&#x4E0D;&#x4F20;&#x5165;&#x5BB9;&#x91CF;&#x7684;&#x5927;&#x5C0F;&#xFF0C;&#x5219;&#x5BB9;&#x91CF;&#x548C;&#x521D;&#x59CB;&#x5316;&#x957F;&#x5EA6;&#x76F8;&#x540C;</span>
  arr_3 <span class="token operator">:=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">int</span><span class="token punctuation">{</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">5</span><span class="token punctuation">}</span> <span class="token comment">// &#x5B9A;&#x4E49;&#x65B9;&#x5F0F;&#x4E09;&#xFF1A;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6574;&#x578B;&#x5207;&#x7247;&#xFF0C;&#x957F;&#x5EA6;&#x548C;&#x5BB9;&#x91CF;&#x4E3A;&#x521D;&#x59CB;&#x5316;&#x503C;&#x7684;&#x6570;&#x91CF;5</span>

  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_1 Len:%v, Type:%T\n&quot;</span><span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>arr_1<span class="token punctuation">)</span><span class="token punctuation">,</span> arr_1<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_2 Len:%v, Type:%T\n&quot;</span><span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>arr_2<span class="token punctuation">)</span><span class="token punctuation">,</span> arr_2<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;arr_3 Len:%v, Type:%T\n&quot;</span><span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>arr_3<span class="token punctuation">)</span><span class="token punctuation">,</span> arr_3<span class="token punctuation">)</span>

  <span class="token function">Foreach</span><span class="token punctuation">(</span>arr_1<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;-------------&quot;</span><span class="token punctuation">)</span>

  <span class="token function">Foreach</span><span class="token punctuation">(</span>arr_2<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;-------------&quot;</span><span class="token punctuation">)</span>

  <span class="token function">Foreach</span><span class="token punctuation">(</span>arr_3<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5207;&#x7247;slice&#x4E3A;&#x4F20;&#x5740;&#xFF08;&#x5F62;&#x53C2;&#x65E0;&#x9700;&#x6307;&#x5B9A;&#x6570;&#x7EC4;&#x957F;&#x5EA6;&#xFF09;&#xFF0C;&#x5728;&#x5B50;&#x51FD;&#x6570;&#x5185;&#x6539;&#x53D8;&#xFF0C;&#x5F71;&#x54CD;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">Foreach</span><span class="token punctuation">(</span>arr <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token builtin">int</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">for</span> <span class="token boolean">_</span><span class="token punctuation">,</span> item <span class="token operator">:=</span> <span class="token keyword">range</span> arr <span class="token punctuation">{</span> <span class="token comment">// forr</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>item<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// arr_1 Len:3, Type:[]int</span>
<span class="token comment">// arr_2 Len:4, Type:[]int</span>
<span class="token comment">// arr_3 Len:5, Type:[]int</span>
<span class="token comment">// 0</span>
<span class="token comment">// 0</span>
<span class="token comment">// 0</span>
<span class="token comment">// -------------</span>
<span class="token comment">// 0</span>
<span class="token comment">// 0</span>
<span class="token comment">// 0</span>
<span class="token comment">// 0</span>
<span class="token comment">// -------------</span>
<span class="token comment">// 1</span>
<span class="token comment">// 2</span>
<span class="token comment">// 3</span>
<span class="token comment">// 4</span>
<span class="token comment">// 5</span>
</code></pre>
<h2 id="map-&#x96C6;&#x5408;"><a name="map-&#x96C6;&#x5408;" class="anchor-navigation-ex-anchor" href="#map-&#x96C6;&#x5408;"><i class="fa fa-link" aria-hidden="true"></i></a>2.11. map &#x96C6;&#x5408;</h2>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x58F0;&#x660E;&#x53D8;&#x91CF;&#xFF0C;&#x9ED8;&#x8BA4; map &#x662F; nil</span>
<span class="token comment">// var map_variable map[key_type]value_type</span>

<span class="token comment">// &#x4F7F;&#x7528; make &#x51FD;&#x6570;</span>
<span class="token comment">// map_variable := make(map[key_type]value_type)</span>

<span class="token comment">// &#x4F7F;&#x7528; delete &#x51FD;&#x6570;</span>
<span class="token comment">// delete(map, key)</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  map_1 <span class="token operator">:=</span> <span class="token function">Mode_1</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>map_1<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;----------------------------------&quot;</span><span class="token punctuation">)</span>
  map_2 <span class="token operator">:=</span> <span class="token function">Mode_2</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>map_2<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;----------------------------------&quot;</span><span class="token punctuation">)</span>
  map_3 <span class="token operator">:=</span> <span class="token function">Mode_3</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>map_3<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;----------------------------------&quot;</span><span class="token punctuation">)</span>
  <span class="token keyword">for</span> k<span class="token punctuation">,</span> v <span class="token operator">:=</span> <span class="token keyword">range</span> map_3 <span class="token punctuation">{</span> <span class="token comment">// &#x904D;&#x5386;map</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Key =&quot;</span><span class="token punctuation">,</span> k<span class="token punctuation">,</span> <span class="token string">&quot;Value =&quot;</span><span class="token punctuation">,</span> v<span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;----------------------------------&quot;</span><span class="token punctuation">)</span>

  exists_two <span class="token operator">:=</span> map_1<span class="token punctuation">[</span><span class="token string">&quot;two&quot;</span><span class="token punctuation">]</span>   <span class="token comment">// &#x4ECE;map_1&#x83B7;&#x53D6;two&#x7684;&#x503C;</span>
  exists_five <span class="token operator">:=</span> map_1<span class="token punctuation">[</span><span class="token string">&quot;five&quot;</span><span class="token punctuation">]</span> <span class="token comment">// &#x4ECE;map_1&#x83B7;&#x53D6;five&#x7684;&#x503C;</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;map_1 exists &apos;two&apos;&#xFF1A;&quot;</span><span class="token punctuation">,</span> exists_two<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;map_1 exists &apos;five&apos;&#xFF1A;&quot;</span><span class="token punctuation">,</span> exists_five<span class="token punctuation">)</span>

  <span class="token function">delete</span><span class="token punctuation">(</span>map_1<span class="token punctuation">,</span> <span class="token string">&quot;two&quot;</span><span class="token punctuation">)</span> <span class="token comment">// &#x5220;&#x9664;two&#x7684;&#x503C;</span>
  exists_two <span class="token operator">=</span> map_1<span class="token punctuation">[</span><span class="token string">&quot;two&quot;</span><span class="token punctuation">]</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;map_1 exists &apos;two&apos;&#xFF1A;&quot;</span><span class="token punctuation">,</span> exists_two<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x521B;&#x5EFA;&#x65B9;&#x5F0F;&#x4E00;</span>
<span class="token keyword">func</span> <span class="token function">Mode_1</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> map_1 <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token builtin">string</span> <span class="token comment">// &#x58F0;&#x660E;</span>
  <span class="token keyword">if</span> map_1 <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>           <span class="token comment">// &#x5224;&#x65AD;&#x4E3A;nil</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Type_1.map_1 is nil&quot;</span><span class="token punctuation">)</span>
    map_1 <span class="token operator">=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">string</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">)</span> <span class="token comment">// &#x521B;&#x5EFA;&#x521D;&#x59CB;&#x957F;&#x5EA6;&#x4E3A;5&#x7684;map</span>
    map_1<span class="token punctuation">[</span><span class="token string">&quot;one&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;Golang&quot;</span>            <span class="token comment">// &#x8D4B;&#x503C;</span>
    map_1<span class="token punctuation">[</span><span class="token string">&quot;two&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;C#&quot;</span>                <span class="token comment">// &#x8D4B;&#x503C;</span>
    map_1<span class="token punctuation">[</span><span class="token string">&quot;three&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;javascript&quot;</span>      <span class="token comment">// &#x8D4B;&#x503C;</span>
    map_1<span class="token punctuation">[</span><span class="token string">&quot;ten&quot;</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;java&quot;</span>              <span class="token comment">// &#x8D4B;&#x503C;&#xFF08;&#x8D85;&#x51FA;&#x5BB9;&#x91CF;&#x4F1A;&#x52A8;&#x6001;&#x589E;&#x52A0;&#x957F;&#x5EA6;&#xFF09;</span>
  <span class="token punctuation">}</span>

  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;map_1 &#x957F;&#x5EA6;&#xFF1A;%v\n&quot;</span><span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>map_1<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">return</span> map_1
<span class="token punctuation">}</span>

<span class="token comment">// &#x521B;&#x5EFA;&#x65B9;&#x5F0F;&#x4E8C;</span>
<span class="token keyword">func</span> <span class="token function">Mode_2</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span><span class="token builtin">string</span> <span class="token punctuation">{</span>
  map_2 <span class="token operator">:=</span> <span class="token function">make</span><span class="token punctuation">(</span><span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token comment">// &#x901A;&#x8FC7;make&#x58F0;&#x660E;&#x5E76;&#x521B;&#x5EFA;&#x521D;&#x59CB;&#x957F;&#x5EA6;&#x4E3A;0&#x7684;map</span>
  map_2<span class="token punctuation">[</span><span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;Golang&quot;</span>
  map_2<span class="token punctuation">[</span><span class="token number">2</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;C#&quot;</span>
  map_2<span class="token punctuation">[</span><span class="token number">3</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;javascript&quot;</span>
  map_2<span class="token punctuation">[</span><span class="token number">10</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">&quot;java&quot;</span>

  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;map_2 &#x957F;&#x5EA6;&#xFF1A;%v\n&quot;</span><span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>map_2<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">return</span> map_2
<span class="token punctuation">}</span>

<span class="token comment">// &#x58F0;&#x660E;&#x548C;&#x521B;&#x5EFA;&#x65B9;&#x5F0F;&#x4E8C;</span>
<span class="token keyword">func</span> <span class="token function">Mode_3</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span><span class="token builtin">string</span> <span class="token punctuation">{</span>
  map_3 <span class="token operator">:=</span> <span class="token keyword">map</span><span class="token punctuation">[</span><span class="token builtin">int</span><span class="token punctuation">]</span><span class="token builtin">string</span><span class="token punctuation">{</span>
    <span class="token number">1</span><span class="token punctuation">:</span>  <span class="token string">&quot;Golang&quot;</span><span class="token punctuation">,</span>
    <span class="token number">2</span><span class="token punctuation">:</span>  <span class="token string">&quot;C#&quot;</span><span class="token punctuation">,</span>
    <span class="token number">3</span><span class="token punctuation">:</span>  <span class="token string">&quot;javascript&quot;</span><span class="token punctuation">,</span>
    <span class="token number">10</span><span class="token punctuation">:</span> <span class="token string">&quot;java&quot;</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span>

  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;map_3 &#x957F;&#x5EA6;&#xFF1A;%v\n&quot;</span><span class="token punctuation">,</span> <span class="token function">len</span><span class="token punctuation">(</span>map_3<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token keyword">return</span> map_3
<span class="token punctuation">}</span>

<span class="token comment">// Type_1.map_1 is nil</span>
<span class="token comment">// map_1 &#x957F;&#x5EA6;&#xFF1A;4</span>
<span class="token comment">// map[one:Golang ten:java three:javascript two:C#]</span>
<span class="token comment">// ----------------------------------</span>
<span class="token comment">// map_2 &#x957F;&#x5EA6;&#xFF1A;4</span>
<span class="token comment">// map[1:Golang 2:C# 3:javascript 10:java]</span>
<span class="token comment">// ----------------------------------</span>
<span class="token comment">// map_3 &#x957F;&#x5EA6;&#xFF1A;4</span>
<span class="token comment">// map[1:Golang 2:C# 3:javascript 10:java]</span>
<span class="token comment">// ----------------------------------</span>
<span class="token comment">// Key = 1 Value = Golang</span>
<span class="token comment">// Key = 2 Value = C#</span>
<span class="token comment">// Key = 3 Value = javascript</span>
<span class="token comment">// Key = 10 Value = java</span>
<span class="token comment">// ----------------------------------</span>
<span class="token comment">// map_1 exists &apos;two&apos;&#xFF1A; C#</span>
<span class="token comment">// map_1 exists &apos;five&apos;&#xFF1A; </span>
<span class="token comment">// map_1 exists &apos;two&apos;&#xFF1A;</span>
</code></pre>
<h2 id="struct-&#x7ED3;&#x6784;&#x4F53;"><a name="struct-&#x7ED3;&#x6784;&#x4F53;" class="anchor-navigation-ex-anchor" href="#struct-&#x7ED3;&#x6784;&#x4F53;"><i class="fa fa-link" aria-hidden="true"></i></a>2.12. struct &#x7ED3;&#x6784;&#x4F53;</h2>
<pre class="language-"><code class="lang-go"><span class="token comment">// struct&#x7ED3;&#x6784;&#x4F53;&#x4F5C;&#x53C2;&#x6570;&#x65F6;&#x662F;&#x4F20;&#x503C;</span>
<span class="token comment">// &#x5B9A;&#x4E49;&#x7ED3;&#x6784;&#x4F53;&#xFF08;&#x5B9A;&#x4E49;&#x7684;&#x7ED3;&#x6784;&#x4F53;&#x5982;&#x679C;&#x53EA;&#x5728;&#x5F53;&#x524D;&#x5305;&#x5185;&#x4F7F;&#x7528;&#xFF0C;&#x7ED3;&#x6784;&#x4F53;&#x7684;&#x5C5E;&#x6027;&#x4E0D;&#x7528;&#x533A;&#x5206;&#x5927;&#x5C0F;&#x5199;&#x3002;&#x5982;&#x679C;&#x60F3;&#x8981;&#x88AB;&#x5176;&#x4ED6;&#x7684;&#x5305;&#x5F15;&#x7528;&#xFF0C;&#x90A3;&#x4E48;&#x7ED3;&#x6784;&#x4F53;&#x7684;&#x5C5E;&#x6027;&#x7684;&#x9996;&#x5B57;&#x6BCD;&#x9700;&#x8981;&#x5927;&#x5199;&#x3002;&#x7ED3;&#x6784;&#x4F53;&#x5C0F;&#x5199;&#x5F00;&#x5934;&#x7684;&#x5C5E;&#x6027;&#x53EA;&#x80FD;&#x5305;&#x5185;&#x8C03;&#x7528;&#xFF09;</span>
<span class="token keyword">type</span> People <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  Name     <span class="token builtin">string</span>  <span class="token comment">// &#x5927;&#x5199;&#x5F00;&#x5934;&#x4E3A;public&#xFF08;&#x5F53;&#x8981;&#x5C06;&#x7ED3;&#x6784;&#x4F53;&#x5BF9;&#x8C61;&#x8F6C;&#x6362;&#x4E3A; JSON &#x65F6;&#xFF0C;&#x5BF9;&#x8C61;&#x4E2D;&#x7684;&#x5C5E;&#x6027;&#x9996;&#x5B57;&#x6BCD;&#x5FC5;&#x987B;&#x662F;&#x5927;&#x5199;&#xFF0C;&#x624D;&#x80FD;&#x6B63;&#x5E38;&#x8F6C;&#x6362;&#x4E3A; JSON&#xFF09;</span>
  age      <span class="token builtin">int</span>     <span class="token comment">// &#x5C0F;&#x5199;&#x5F00;&#x5934;&#x4E3A;private&#xFF08;JSON&#x5E8F;&#x5217;&#x5316;&#x65F6;&#x5FFD;&#x7565;private&#x5B57;&#x6BB5;&#xFF09;</span>
  Weight   <span class="token builtin">float32</span> <span class="token string">`json:&quot;-&quot;`</span>    <span class="token comment">// [`json:&quot;-&quot;`]&#x6807;&#x8BB0;&#x8F93;&#x51FA;json&#x65F6;&#x5FFD;&#x7565;&#x8BE5;&#x5B57;&#x6BB5;</span>
  Birthday <span class="token builtin">string</span>  <span class="token string">`json:&quot;bday&quot;`</span> <span class="token comment">// [`json:&quot;bday&quot;`]&#x6807;&#x8BB0;&#x8F93;&#x51FA;&#x7684;json&#x540D;&#x5B57;&#x4E3A;bday</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  yzq <span class="token operator">:=</span> People<span class="token punctuation">{</span>
    Name<span class="token punctuation">:</span>     <span class="token string">&quot;&#x5C39;&#x81EA;&#x5F3A;&quot;</span><span class="token punctuation">,</span>
    age<span class="token punctuation">:</span>      <span class="token number">18</span><span class="token punctuation">,</span>
    Weight<span class="token punctuation">:</span>   <span class="token number">130.5</span><span class="token punctuation">,</span>
    Birthday<span class="token punctuation">:</span> <span class="token string">&quot;2022-01-01&quot;</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span>

  zhangsan <span class="token operator">:=</span> People<span class="token punctuation">{</span><span class="token string">&quot;&#x5F20;&#x4E09;&quot;</span><span class="token punctuation">,</span> <span class="token number">19</span><span class="token punctuation">,</span> <span class="token number">150.8</span><span class="token punctuation">,</span> <span class="token string">&quot;1999-12-31&quot;</span><span class="token punctuation">}</span> <span class="token comment">// &#x6309;&#x7ED3;&#x6784;&#x4F53;&#x5B9A;&#x4E49;&#x987A;&#x5E8F;&#x8D4B;&#x503C;</span>

  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>yzq<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>zhangsan<span class="token punctuation">)</span>
  <span class="token function">rename</span><span class="token punctuation">(</span>yzq<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>yzq<span class="token punctuation">)</span>
  <span class="token function">rename_2</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>yzq<span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>yzq<span class="token punctuation">)</span>

  <span class="token keyword">if</span> result<span class="token punctuation">,</span> err <span class="token operator">:=</span> json<span class="token punctuation">.</span><span class="token function">Marshal</span><span class="token punctuation">(</span>yzq<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;JSON =&quot;</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x4F20;&#x503C;</span>
<span class="token keyword">func</span> <span class="token function">rename</span><span class="token punctuation">(</span>people People<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  people<span class="token punctuation">.</span>Name <span class="token operator">=</span> <span class="token string">&quot;&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;&quot;</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x4F20;&#x5740;</span>
<span class="token keyword">func</span> <span class="token function">rename_2</span><span class="token punctuation">(</span>people <span class="token operator">*</span>People<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  people<span class="token punctuation">.</span>Name <span class="token operator">=</span> <span class="token string">&quot;&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;&quot;</span>
<span class="token punctuation">}</span>

<span class="token comment">// {&#x5C39;&#x81EA;&#x5F3A; 18 130.5 2022-01-01}</span>
<span class="token comment">// {&#x5F20;&#x4E09; 19 150.8 1999-12-31}</span>
<span class="token comment">// {&#x5C39;&#x81EA;&#x5F3A; 18 130.5 2022-01-01}</span>
<span class="token comment">// {&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01; 18 130.5 2022-01-01}</span>
<span class="token comment">// JSON = {&quot;Name&quot;:&quot;&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;&quot;,&quot;bday&quot;:&quot;2022-01-01&quot;}</span>
</code></pre>
<h2 id="oop-&#x9762;&#x5411;&#x5BF9;&#x8C61;"><a name="oop-&#x9762;&#x5411;&#x5BF9;&#x8C61;" class="anchor-navigation-ex-anchor" href="#oop-&#x9762;&#x5411;&#x5BF9;&#x8C61;"><i class="fa fa-link" aria-hidden="true"></i></a>2.13. OOP &#x9762;&#x5411;&#x5BF9;&#x8C61;</h2>
<h3 id="&#x5C01;&#x88C5;"><a name="&#x5C01;&#x88C5;" class="anchor-navigation-ex-anchor" href="#&#x5C01;&#x88C5;"><i class="fa fa-link" aria-hidden="true"></i></a>2.13.1. &#x5C01;&#x88C5;</h3>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x4E3A;&#x7ED3;&#x6784;&#x4F53;&#x7ED1;&#x5B9A;&#x65B9;&#x6CD5;</span>
<span class="token comment">// func (variable_name variable_type) func_name() [return_type]{</span>
<span class="token comment">//    /* &#x51FD;&#x6570;&#x4F53;*/</span>
<span class="token comment">// }</span>

<span class="token comment">// people&#x7C7B;&#x9996;&#x5B57;&#x6BCD;&#x5C0F;&#x5199;&#xFF0C;&#x4E3A;private&#x79C1;&#x6709;&#x7C7B;</span>
<span class="token keyword">type</span> people <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  Name     <span class="token builtin">string</span>
  age      <span class="token builtin">uint8</span>
  Weight   <span class="token builtin">float32</span> <span class="token string">`json:&quot;-&quot;`</span>    <span class="token comment">// [`json:&quot;-&quot;`]&#x6807;&#x8BB0;&#x8F93;&#x51FA;json&#x65F6;&#x5FFD;&#x7565;&#x8BE5;&#x5B57;&#x6BB5;</span>
  Birthday <span class="token builtin">string</span>  <span class="token string">`json:&quot;bday&quot;`</span> <span class="token comment">// [`json:&quot;bday&quot;`]&#x6807;&#x8BB0;&#x8F93;&#x51FA;&#x7684;json&#x540D;&#x5B57;&#x4E3A;bday</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x9996;&#x5B57;&#x6BCD;&#x5927;&#x5199;&#xFF0C;&#x5B9A;&#x4E49;&#x7C7B;&#x7684;public&#x516C;&#x6709;&#x65B9;&#x6CD5;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_people people<span class="token punctuation">)</span> <span class="token function">Show</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;&#x59D3;&#x540D;&#xFF1A;%v&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;%v&#xFF0C;&#x4F53;&#x91CD;&#xFF1A;%v\n&quot;</span><span class="token punctuation">,</span> _people<span class="token punctuation">.</span>Name<span class="token punctuation">,</span> _people<span class="token punctuation">.</span>age<span class="token punctuation">,</span> _people<span class="token punctuation">.</span>Weight<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// struct&#x7C7B;&#x578B;&#x4F5C;&#x53C2;&#x6570;&#x65F6;&#x662F;&#x4F20;&#x503C;&#xFF0C;&#x6240;&#x4EE5;&#x5728;&#x65B9;&#x6CD5;&#x5185;&#x4FEE;&#x6539;&#x503C;&#xFF0C;&#x5728;&#x5916;&#x90E8;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x4E0D;&#x751F;&#x6548;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_people people<span class="token punctuation">)</span> <span class="token function">rename_1</span><span class="token punctuation">(</span>new_name <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  _people<span class="token punctuation">.</span>Name <span class="token operator">=</span> new_name <span class="token comment">// &#x6B64;&#x5904;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x6709;&#x63D0;&#x793A;&#x4FEE;&#x6539;&#x503C;&#x65E0;&#x6548;</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x901A;&#x8FC7;&#x6307;&#x9488;&#x4F20;&#x5740;&#xFF0C;&#x5728;&#x65B9;&#x6CD5;&#x5185;&#x4FEE;&#x6539;&#x503C;&#xFF0C;&#x5728;&#x5916;&#x90E8;&#x4E3B;&#x51FD;&#x6570;&#x4E2D;&#x6709;&#x6548;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_people <span class="token operator">*</span>people<span class="token punctuation">)</span> <span class="token function">rename_2</span><span class="token punctuation">(</span>new_name <span class="token builtin">string</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  _people<span class="token punctuation">.</span>Name <span class="token operator">=</span> new_name
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token punctuation">(</span>_people <span class="token operator">*</span>people<span class="token punctuation">)</span> <span class="token function">getname</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> _people<span class="token punctuation">.</span>Name
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  yzq <span class="token operator">:=</span> people<span class="token punctuation">{</span>
    Name<span class="token punctuation">:</span>     <span class="token string">&quot;&#x5C39;&#x81EA;&#x5F3A;&quot;</span><span class="token punctuation">,</span>
    age<span class="token punctuation">:</span>      <span class="token number">18</span><span class="token punctuation">,</span>
    Weight<span class="token punctuation">:</span>   <span class="token number">130.5</span><span class="token punctuation">,</span>
    Birthday<span class="token punctuation">:</span> <span class="token string">&quot;2022-01-01&quot;</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span>

  yzq<span class="token punctuation">.</span><span class="token function">Show</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  yzq<span class="token punctuation">.</span><span class="token function">rename_1</span><span class="token punctuation">(</span><span class="token string">&quot;&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;1&quot;</span><span class="token punctuation">)</span>
  yzq<span class="token punctuation">.</span><span class="token function">Show</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  yzq<span class="token punctuation">.</span><span class="token function">rename_2</span><span class="token punctuation">(</span><span class="token string">&quot;&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;2&quot;</span><span class="token punctuation">)</span>
  yzq<span class="token punctuation">.</span><span class="token function">Show</span><span class="token punctuation">(</span><span class="token punctuation">)</span>

  name <span class="token operator">:=</span> yzq<span class="token punctuation">.</span><span class="token function">getname</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>name<span class="token punctuation">)</span>

  <span class="token keyword">if</span> result<span class="token punctuation">,</span> err <span class="token operator">:=</span> json<span class="token punctuation">.</span><span class="token function">Marshal</span><span class="token punctuation">(</span>yzq<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;JSON =&quot;</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x59D3;&#x540D;&#xFF1A;&#x5C39;&#x81EA;&#x5F3A;&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;18&#xFF0C;&#x4F53;&#x91CD;&#xFF1A;130.5</span>
<span class="token comment">// &#x59D3;&#x540D;&#xFF1A;&#x5C39;&#x81EA;&#x5F3A;&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;18&#xFF0C;&#x4F53;&#x91CD;&#xFF1A;130.5</span>
<span class="token comment">// &#x59D3;&#x540D;&#xFF1A;&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;2&#xFF0C;&#x5E74;&#x9F84;&#xFF1A;18&#xFF0C;&#x4F53;&#x91CD;&#xFF1A;130.5</span>
<span class="token comment">// &#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;2</span>
<span class="token comment">// JSON = {&quot;Name&quot;:&quot;&#x4ECA;&#x665A;&#x51FA;&#x569F;&#x5A01;2&quot;,&quot;bday&quot;:&quot;2022-01-01&quot;}</span>
</code></pre>
<h3 id="&#x7EE7;&#x627F;"><a name="&#x7EE7;&#x627F;" class="anchor-navigation-ex-anchor" href="#&#x7EE7;&#x627F;"><i class="fa fa-link" aria-hidden="true"></i></a>2.13.2. &#x7EE7;&#x627F;</h3>
<pre class="language-"><code class="lang-go"><span class="token comment">// Golang&#x4E2D;&#x7EE7;&#x627F;&#x7C7B;&#x4F3C;&#x4E8E;&#x7EC4;&#x5408;&#x5F62;&#x5F0F;</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x7236;&#x7C7B;Human</span>
<span class="token keyword">type</span> Human <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  Name <span class="token builtin">string</span>
  Sex  <span class="token builtin">uint8</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x7236;&#x7C7B;&#x65B9;&#x6CD5;Eat</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_human <span class="token operator">*</span>Human<span class="token punctuation">)</span> <span class="token function">Eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Human Eat&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x7236;&#x7C7B;&#x65B9;&#x6CD5;Talk</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_human <span class="token operator">*</span>Human<span class="token punctuation">)</span> <span class="token function">Talk</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Human Talk&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x5B50;&#x7C7B;</span>
<span class="token keyword">type</span> Superman <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  Human <span class="token comment">// &#x2605;&#x7EE7;&#x627F;Human&#x7C7B;</span>
  Level <span class="token builtin">uint</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x91CD;&#x5199;&#x7236;&#x7C7B;Eat&#x65B9;&#x6CD5;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_superman <span class="token operator">*</span>Superman<span class="token punctuation">)</span> <span class="token function">Eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Superman Eat&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B50;&#x7C7B;&#x81EA;&#x6709;&#x65B9;&#x6CD5;Fly</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_superman <span class="token operator">*</span>Superman<span class="token punctuation">)</span> <span class="token function">Fly</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Superman Fly&quot;</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">// &#x521D;&#x59CB;&#x5316;&#x65B9;&#x5F0F;&#x4E00;&#xFF1A;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x5148;&#x8D4B;&#x503C;&#x7236;&#x7C7B;&#x518D;&#x8D4B;&#x503C;&#x5B50;&#x7C7B;&#xFF0C;&#x591A;&#x5C42;&#x7EE7;&#x627F;&#x8981;&#x906D;&#x7F6A;</span>
  <span class="token comment">// yzq := Superman{Human{Name: &quot;&#x5C39;&#x81EA;&#x5F3A;&quot;, Sex: 1}, 99}</span>

  <span class="token comment">// &#x521D;&#x59CB;&#x5316;&#x65B9;&#x5F0F;&#x4E8C;&#xFF1A;&#x5148;&#x58F0;&#x660E;&#x5B50;&#x7C7B;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7;&#x70B9;&#x53F7;&#x9010;&#x4E2A;&#x8D4B;&#x503C;</span>
  <span class="token comment">//var yzq Superman</span>
  <span class="token keyword">var</span> yzq <span class="token operator">=</span> <span class="token function">new</span><span class="token punctuation">(</span>Superman<span class="token punctuation">)</span>
  yzq<span class="token punctuation">.</span>Name <span class="token operator">=</span> <span class="token string">&quot;&#x5C39;&#x81EA;&#x5F3A;&quot;</span>
  yzq<span class="token punctuation">.</span>Sex <span class="token operator">=</span> <span class="token number">1</span>
  yzq<span class="token punctuation">.</span>Level <span class="token operator">=</span> <span class="token number">99</span>

  yzq<span class="token punctuation">.</span><span class="token function">Eat</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment">// Superman.Eat()</span>
  yzq<span class="token punctuation">.</span><span class="token function">Talk</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// Human.Talk()</span>
  yzq<span class="token punctuation">.</span><span class="token function">Fly</span><span class="token punctuation">(</span><span class="token punctuation">)</span>  <span class="token comment">// Superman.Fly()</span>

  <span class="token keyword">if</span> result<span class="token punctuation">,</span> err <span class="token operator">:=</span> json<span class="token punctuation">.</span><span class="token function">Marshal</span><span class="token punctuation">(</span>yzq<span class="token punctuation">)</span><span class="token punctuation">;</span> err <span class="token operator">==</span> <span class="token boolean">nil</span> <span class="token punctuation">{</span>
    fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;Superman =&quot;</span><span class="token punctuation">,</span> <span class="token function">string</span><span class="token punctuation">(</span>result<span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>

<span class="token comment">// Superman Eat</span>
<span class="token comment">// Human Talk</span>
<span class="token comment">// Superman Fly</span>
<span class="token comment">// Superman = {&quot;Name&quot;:&quot;&#x5C39;&#x81EA;&#x5F3A;&quot;,&quot;Sex&quot;:1,&quot;Level&quot;:99}</span>
</code></pre>
<h3 id="&#x591A;&#x6001;"><a name="&#x591A;&#x6001;" class="anchor-navigation-ex-anchor" href="#&#x591A;&#x6001;"><i class="fa fa-link" aria-hidden="true"></i></a>2.13.3. &#x591A;&#x6001;</h3>
<pre class="language-"><code class="lang-go"><span class="token comment">// interface &#x672C;&#x8D28;&#x662F;&#x4E00;&#x4E2A;&#x6307;&#x9488;</span>
<span class="token comment">// &#x5B9A;&#x4E49;&#x63A5;&#x53E3;</span>
<span class="token comment">// type interface_name interface {</span>
<span class="token comment">//   method_name1 [return_type]</span>
<span class="token comment">//   method_name2 [return_type]</span>
<span class="token comment">//   // ...</span>
<span class="token comment">//   method_nameX [return_type]</span>
<span class="token comment">// }</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x52A8;&#x7269;&#x63A5;&#x53E3;IAnimal</span>
<span class="token keyword">type</span> IAnimal <span class="token keyword">interface</span> <span class="token punctuation">{</span>
  <span class="token function">Sleep</span><span class="token punctuation">(</span><span class="token punctuation">)</span>          <span class="token comment">// &#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;Sleep()</span>
  <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token comment">// &#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;GetName()&#x83B7;&#x53D6;&#x540D;&#x79F0;</span>
  <span class="token function">GetKind</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token comment">// &#x5B9A;&#x4E49;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;GetKind()&#x83B7;&#x53D6;&#x79CD;&#x7C7B;</span>
<span class="token punctuation">}</span>

<span class="token comment">// -----------------------------------------------------------------</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x732B;&#x7C7B;&#xFF08;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x5168;&#x90E8;&#x65B9;&#x6CD5;&#xFF09;</span>
<span class="token keyword">type</span> Cat <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  Name <span class="token builtin">string</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;Sleep()</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_animal <span class="token operator">*</span>Cat<span class="token punctuation">)</span> <span class="token function">Sleep</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v Sleep\r&quot;</span><span class="token punctuation">,</span> _animal<span class="token punctuation">.</span>Name<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;GetName()</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_animal <span class="token operator">*</span>Cat<span class="token punctuation">)</span> <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> _animal<span class="token punctuation">.</span>Name
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;GetKind()</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_animal <span class="token operator">*</span>Cat<span class="token punctuation">)</span> <span class="token function">GetKind</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">&quot;Animal Kind %T\r&quot;</span><span class="token punctuation">,</span> _animal<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// -----------------------------------------------------------------</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x8001;&#x9F20;&#x7C7B;&#xFF08;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x5168;&#x90E8;&#x65B9;&#x6CD5;&#xFF09;</span>
<span class="token keyword">type</span> Mouse <span class="token keyword">struct</span> <span class="token punctuation">{</span>
  Name <span class="token builtin">string</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;Sleep()</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_animal <span class="token operator">*</span>Mouse<span class="token punctuation">)</span> <span class="token function">Sleep</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  fmt<span class="token punctuation">.</span><span class="token function">Printf</span><span class="token punctuation">(</span><span class="token string">&quot;%v Sleep\r&quot;</span><span class="token punctuation">,</span> _animal<span class="token punctuation">.</span>Name<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;GetName()</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_animal <span class="token operator">*</span>Mouse<span class="token punctuation">)</span> <span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> _animal<span class="token punctuation">.</span>Name
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x65B9;&#x6CD5;GetKind()</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>_animal <span class="token operator">*</span>Mouse<span class="token punctuation">)</span> <span class="token function">GetKind</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> fmt<span class="token punctuation">.</span><span class="token function">Sprintf</span><span class="token punctuation">(</span><span class="token string">&quot;Animal Kind %T\r&quot;</span><span class="token punctuation">,</span> _animal<span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// -----------------------------------------------------------------</span>

<span class="token comment">// &#x63A5;&#x53E3;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x9012;</span>
<span class="token keyword">func</span> <span class="token function">ShowAnimal</span><span class="token punctuation">(</span>_animal IAnimal<span class="token punctuation">)</span> <span class="token punctuation">{</span>
  _animal<span class="token punctuation">.</span><span class="token function">Sleep</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;&#x540D;&#x79F0;&#xFF1A;&quot;</span><span class="token punctuation">,</span> _animal<span class="token punctuation">.</span><span class="token function">GetName</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>_animal<span class="token punctuation">.</span><span class="token function">GetKind</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  cat <span class="token operator">:=</span> Cat<span class="token punctuation">{</span>Name<span class="token punctuation">:</span> <span class="token string">&quot;&#x6C64;&#x59C6;&quot;</span><span class="token punctuation">}</span>
  <span class="token function">ShowAnimal</span><span class="token punctuation">(</span><span class="token operator">&amp;</span>cat<span class="token punctuation">)</span>

  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span><span class="token string">&quot;-------------------------&quot;</span><span class="token punctuation">)</span>

  <span class="token keyword">var</span> mouse <span class="token operator">=</span> <span class="token function">new</span><span class="token punctuation">(</span>Mouse<span class="token punctuation">)</span> <span class="token comment">// &#x901A;&#x8FC7;new&#x521B;&#x5EFA;&#x7684;&#x5BF9;&#x8C61;&#x4E3A;&#x6307;&#x9488;</span>
  mouse<span class="token punctuation">.</span>Name <span class="token operator">=</span> <span class="token string">&quot;&#x6770;&#x745E;&quot;</span>
  <span class="token function">ShowAnimal</span><span class="token punctuation">(</span>mouse<span class="token punctuation">)</span> <span class="token comment">// &#x6240;&#x4EE5;&#x4F20;&#x5165;&#x8BE5;&#x65B9;&#x6CD5;&#x65F6;&#xFF0C;&#x4E0D;&#x9700;&#x8981;&#x52A0;&#x524D;&#x7F00;&amp;</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x6C64;&#x59C6; Sleep</span>
<span class="token comment">// &#x540D;&#x79F0;&#xFF1A; &#x6C64;&#x59C6;</span>
<span class="token comment">// Animal Kind *main.Cat</span>
<span class="token comment">// -------------------------</span>
<span class="token comment">// &#x6770;&#x745E; Sleep</span>
<span class="token comment">// &#x540D;&#x79F0;&#xFF1A; &#x6770;&#x745E;</span>
<span class="token comment">// Animal Kind *main.Mouse</span>
</code></pre>
<blockquote>
<p>&#x7EC4;&#x5408;&#x63A5;&#x53E3;</p>
</blockquote>
<pre class="language-"><code class="lang-go"><span class="token comment">// &#x5B9A;&#x4E49;&#x8BFB;&#x63A5;&#x53E3;</span>
<span class="token keyword">type</span> reader <span class="token keyword">interface</span> <span class="token punctuation">{</span>
  <span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x5199;&#x63A5;&#x53E3;</span>
<span class="token keyword">type</span> writer <span class="token keyword">interface</span> <span class="token punctuation">{</span>
  <span class="token function">write</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x8BFB;&#x5199;&#x63A5;&#x53E3;</span>
<span class="token keyword">type</span> reader_writer <span class="token keyword">interface</span> <span class="token punctuation">{</span>
  reader
  writer
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9A;&#x4E49;&#x5B9E;&#x73B0;&#x7C7B;&#xFF08;&#x5FC5;&#x987B;&#x5B9E;&#x73B0;&#x63A5;&#x53E3;&#x5168;&#x90E8;&#x65B9;&#x6CD5;&#xFF09;</span>
<span class="token keyword">type</span> mouse <span class="token keyword">struct</span><span class="token punctuation">{</span><span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x8BFB;&#x63A5;&#x53E3;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>m mouse<span class="token punctuation">)</span> <span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token string">&quot;mouse reading...&quot;</span>
<span class="token punctuation">}</span>

<span class="token comment">// &#x5B9E;&#x73B0;&#x5199;&#x63A5;&#x53E3;</span>
<span class="token keyword">func</span> <span class="token punctuation">(</span>m <span class="token operator">*</span>mouse<span class="token punctuation">)</span> <span class="token function">write</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token builtin">string</span> <span class="token punctuation">{</span>
  <span class="token keyword">return</span> <span class="token string">&quot;mouse writing...&quot;</span>
<span class="token punctuation">}</span>

<span class="token keyword">func</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> rw <span class="token operator">=</span> <span class="token function">new</span><span class="token punctuation">(</span>mouse<span class="token punctuation">)</span>

  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>rw<span class="token punctuation">.</span><span class="token function">read</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  fmt<span class="token punctuation">.</span><span class="token function">Println</span><span class="token punctuation">(</span>rw<span class="token punctuation">.</span><span class="token function">write</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// mouse reading...</span>
<span class="token comment">// mouse writing...</span>
</code></pre>
<hr>
<h1 id="&#x5E38;&#x7528;&#x547D;&#x4EE4;"><a name="&#x5E38;&#x7528;&#x547D;&#x4EE4;" class="anchor-navigation-ex-anchor" href="#&#x5E38;&#x7528;&#x547D;&#x4EE4;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x5E38;&#x7528;&#x547D;&#x4EE4;</h1>
<pre class="language-"><code class="lang-bash">// &#x67E5;&#x770B;Golang&#x7248;&#x672C;
<span class="token operator">&gt;</span> go version

// &#x67E5;&#x770B;&#x73AF;&#x5883;&#x914D;&#x7F6E;
<span class="token operator">&gt;</span> go <span class="token function">env</span>

// <span class="token assign-left variable">GO111MODULE</span><span class="token operator">=</span>on &#x4EE5;&#x540E;&#xFF0C;&#x4E0B;&#x8F7D;&#x7684;&#x6A21;&#x5757;&#x5185;&#x5BB9;&#x4F1A;&#x7F13;&#x5B58;&#x5728; <span class="token variable">$GOPATH</span>/pkg/mod &#x76EE;&#x5F55;&#x4E2D;&#x3002;&#x4F7F;&#x7528;&#x4EE5;&#x4E0B;&#x547D;&#x4EE4;&#x53EF;&#x6E05;&#x7A7A;&#x7F13;&#x5B58;&#xFF1A;
<span class="token operator">&gt;</span> go clean <span class="token parameter variable">--modcache</span>

---

// xxx
<span class="token operator">&gt;</span> xxx
</code></pre>
<footer class="page-footer"><span class="copyright">&#xA9; &#x5C39;&#x81EA;&#x5F3A; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification"><a id="link_icp" href="http://www.beian.miit.gov.cn/" target="_blank">&#x7CA4;ICP&#x5907;18161097&#x53F7;</a>&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;
2024-05-11 11:35:37
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../" class="navigation navigation-prev " aria-label="Previous page: 在线笔记">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Golang.html#安装与配置" class="navigation navigation-next " aria-label="Next page: 安装与配置">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Golang","level":"1.2","depth":1,"next":{"title":"安装与配置","level":"1.2.1","depth":2,"anchor":"#安装与配置","path":"chapter/Golang.md","ref":"chapter/Golang.md#安装与配置","articles":[]},"previous":{"title":"在线笔记","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","-lunr","-search","search-pro","anchor-navigation-ex","splitter","github","tbfed-pagefooter","prism","alerts","donate","copy-code-button","advanced-emoji","expandable-chapters"],"styles":{"website":"styles/yzq.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"&copy 尹自强","modify_label":"<a id='link_icp' href='http://www.beian.miit.gov.cn/' target='blank'>粤ICP备18161097号</a>文件修订时间","modify_format":"YYYY-MM-DD HH:mm:ss"},"prism":{},"github":{"url":"https://github.com/554393109"},"splitter":{},"search-pro":{},"donate":{"alipay":"../../assets/donate_alipay.jpg","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"../../assets/donate_wechat.jpg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":1},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"alerts":{},"copy-code-button":{},"advanced-emoji":{"embedEmojis":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","author":"尹自强","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"尹自强.Note","language":"zh-hans","links":{"sidebar":{"作者GitHub":"https://github.com/554393109"}},"gitbook":"3.2.3","description":"尹自强.Note"},"file":{"path":"chapter/Golang.md","mtime":"2024-05-11T03:35:37.532Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2025-01-16T03:02:01.896Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-alerts/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

